【TC SRM 718 DIV 2 A】RelativeHeights
【Link】:
【Description】
给你n个数字组成原数列;
然后,让你生成n个新的数列a
其中第i个数列ai为删掉原数列中第i个数字后剩余的数字组成的数列;
然后问你这n个数列组成的排序数组(即按照把第i个位置上的数改为第i大的数在未改变之前数组中的位置这个规则转化成的数组);
有多少种不同类型
【Solution】
首先,枚举第i个数字被删掉了;
然后用结构体来存剩下的n-1个数字形成的数组,
(存数值和下标)
然后排序,获取第i大的数的下标;
存到vector里面,用map< vector < int >,int>来判重;
【NumberOf WA】
0
【Reviw】
map判重很方便。
遇到要知道下标的,一般都用结构体排序吧;
【Code】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
//head
struct abc{
int x,id;
};
abc a[N];
map <vector <int>,int > dic;
bool cmp(abc a,abc b){
return a.x > b.x;
}
class RelativeHeights
{
public:
int countWays(vector <int> h)
{
int ans = 0;
dic.clear();
int len = h.size(),n;
vector <int> v;
rep1(i,0,len-1){
n = 0;
rep1(j,0,len-1)
if (i!=j){
n++;
a[n].id = n-1,a[n].x = h[j];
}
sort(a+1,a+1+n,cmp);
v.clear();
rep1(j,1,n){
v.pb(a[j].id);
}
if (!dic[v]){
ans++;
dic[v] = 1;
}
}
return ans;
}
};
【TC SRM 718 DIV 2 A】RelativeHeights的更多相关文章
- 【TC SRM 718 DIV 2 B】Reconstruct Graph
[Link]: [Description] 给你两个括号序列; 让你把这两个括号序列合并起来 (得按顺序合并) 使得组成的新的序列为合法序列; 即每个括号都能匹配; 问有多少种合并的方法; [Solu ...
- 【topcoder SRM 702 DIV 2 250】TestTaking
Problem Statement Recently, Alice had to take a test. The test consisted of a sequence of true/false ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【SRM 716 DIV 1 A】 ConstructLCS
Problem Statement A string S is a subsequence of a string T if we can obtain S from T by erasing som ...
- 【Codeforces Round #434 (Div. 1) B】Polycarp's phone book
[链接]h在这里写链接 [题意] 给你n个电话号码. 让你给每一个电话号码选定一个字符串s; 使得这个串s是这个电话号码的子串. 且不是任何一个其他电话号码的子串. s要求最短. [题解] 字典树. ...
- 【Codeforces Round #493 (Div. 2) B】Cutting
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然只有在前i个位置奇数偶数出现次数都相同的地方才能切. (且不管前面怎么切,这里都能切的. 那么就相当于有n个物品,每个物品的代价 ...
- 【Codeforces Round #499 (Div. 1) B】Rocket
[链接] 我是链接,点我呀:) [题意] 让你猜到火星的距离x是多少. 已知1<=x<=m 然后你可以问系统最多60个问题 问题的形式以一个整数y表示 然后系统会回答你3种结果 -1 x& ...
- 【Codeforces Round #499 (Div. 2) E】Border
[链接] 我是链接,点我呀:) [题意] 给你n个数字,每个数字可以无限用,每种方案可以组成一个和,问你%k的结果有多少种不同的结果. [题解] 相当于给你一个方程 \(x_1*a_1+x_2*a_2 ...
- 【Codeforces Round #483 (Div. 2) C】Finite or not?
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 有个性质. 如果p/q是分数的最简形式. 那么p/q能化成有限小数. 当且仅当q的质因数分解形式中只有质因子2和5 (且不能出现其他 ...
随机推荐
- sublime搜索和替换--多文件搜索替换
Search and Replace - Multiple Files Searching To open the search panel for files, press Ctrl + Shift ...
- android开发之Animation(五)
android开发之Animation的使用(五) 本博文主要讲述的是Animation中的AnimationLisenter的用法,以及此类的一些生命周期函数的调用,代码实比例如以下: MainAc ...
- Java实现斐波那契数列Fibonacci
import java.util.Scanner; public class Fibonacci { public static void main(String[] args) { // TODO ...
- git的学习笔记整理
Git学习较好的网址:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001373 ...
- BZOJ4479 [JSOI2013] 吃货jyy 解题报告(三进制状态压缩+欧拉回路)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4479 Description [故事背景]作为JSOI的著名吃货,JYY的理想之一就是吃 ...
- java 8 , merge()
import java.util.HashMap; import java.util.Map; public class j8merge { public static void main(Strin ...
- objc_clear_deallocating 与弱引用
void *objc_destructInstance(id obj){ if (obj) { Class isa_gen = _object_getClass(obj); class_t *isa ...
- The IDL compiler
The IDL compiler or bindings generator transcompiles Web IDL to C++ code, specifically bindings betw ...
- 【Git 一】Linux安装Git
一.Git 的优势 #简单说一下 Git 的优势. 1.版本库本地化,支持离线提交,相对独立不影响协同开发. 2.支持快速切换分支方便合并,比较合并性能好. 3.分布式管理,适应不同的业务场景. 4. ...
- php重新编译,gd扩展支持jpeg文件
晚上写东西的时候,报了一个错误: Call to undefined function imagecreatefromjpeg() 没有开启 jpeg 支持?原来是默认安装的 gd 扩展默认不支持 j ...