【Codeforces Round #424 (Div. 2) A】Unimodal Array
【Link】:http://codeforces.com/contest/831/problem/A
【Description】
让你判断一个数列是不是这样一个数列:
一开始是严格上升
然后开始全都是一个数字
然后又开始严格下降
【Solution】
枚举中间全部相同的是哪个数字;
假设是i..j这一段
则看看1..i是不是严格上升,以及j+1..n是不是严格下降;
如果所有的这样的i..j都不满足则无解;
找到一组则有解;
【NumberOf WA】
0
【Reviw】
找到最特殊的地方;
抓住问题的重点!
【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;
typedef set<int> myset;
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 = 2e3;
struct abc{
int x,id;
};
int k,n,a[N+100],b[N+100],pre[N+100],ans,tot;
map <int,int> dic;
abc c[N*N+10];
bool cmp(abc a,abc b){
return a.x < b.x;
}
int main(){
//Open();
//Close();
scanf("%d%d",&k,&n);
rep1(i,1,k)
scanf("%d",&a[i]);
pre[0] = 0;
rep1(i,1,k)
pre[i] = pre[i-1] + a[i];
rep1(i,1,n)
scanf("%d",&b[i]);
rep1(i,1,k){
rep1(j,1,n){
int x = b[j]-pre[i];
tot++;
c[tot].x = x,c[tot].id = j;
}
}
sort(c+1,c+1+tot,cmp);
rep1(i,1,tot){
int num = n;
int j = i;
while (j+1<=tot && c[j+1].x==c[i].x) j++;
rep1(k,i,j){
if (dic[c[k].id]!=i){
num--;
dic[c[k].id] = i;
}
}
if (num==0) ans++;
i = j;
}
printf("%d\n",ans);
return 0;
}
/*
写完之后,明确每一步的作用
*/
【Codeforces Round #424 (Div. 2) A】Unimodal Array的更多相关文章
- 【Codeforces Round #424 (Div. 2) B】Keyboard Layouts
[Link]:http://codeforces.com/contest/831/problem/B [Description] 两个键盘的字母的位置不一样; 数字键的位置一样; 告诉你第一个键盘按某 ...
- 【Codeforces Round #424 (Div. 2) C】Jury Marks
[Link]:http://codeforces.com/contest/831/problem/C [Description] 有一个人参加一个比赛; 他一开始有一个初始分数x; 有k个评委要依次对 ...
- 【Codeforces Round #424 (Div. 2) D】Office Keys
[Link]:http://codeforces.com/contest/831/problem/D [Description] 有n个人,它们都要去一个终点,终点位于p; 但是,在去终点之前,他们都 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
随机推荐
- hdu5282 最长公共子序列的变形
pid=5282">http://acm.hdu.edu.cn/showproblem.php?pid=5282 Problem Description Xuejiejie loves ...
- HDOJ1084 What Is Your Grade?
What Is Your Grade? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- poj_2299Ultra-QuickSort,树状数组离散化
求逆序数 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...
- 互不侵犯_状压$dp$
如果有想学习状压\(dp\)的童鞋,请光临博客状压\(dp\)初学 互不侵犯 题目描述 在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八 ...
- kali 2.0 linux中的Nmap的操作系统扫描功能
不多说,直接上干货! 可以使用-O选项,让Nmap对目标的操作系统进行识别. msf > nmap -O 202.193.58.13 [*] exec: nmap -O 202.193.58.1 ...
- RecordAccumulator 1
介绍 前面讲过producer会将数据保存在RecordAccumulator中,并通过Sender发送数据.RecordAccumulator 就相当于一个队列保存着那些准备发送到server的数据 ...
- Windows 相关
Open the Windows Update troubleshooter If your computer is having problems finding and installing op ...
- Angular2/Ionic2集成Promact/md2.md
最近想找一套比较完整的基于Material风格的Angular2的控件库,有两个选择一个是Angular官方的Material2,但是这套库的DatePicker控件目前只能支持年月日,不支持时分秒, ...
- 内存,寄存器和cache的区别与联系
1. 寄存器是中央处理器内的组成部份.寄存器是有限存贮容量的高速存贮部件,它们可用来暂存指令.数据和位址.在中央处理器的控制部件中,包含的寄存器有指令寄存器(IR)和程序计数器(PC).在中央处理器的 ...
- 修改MySQL默认字符集
今天发现有库级字符集和表级字符集,实验了下发现,库级字符集是该库内表的默认字符集,当创建表时,如果未指定字符集,默认使用该表所属库的字符集.表也可使用不同于所属库的字符集. MySQL对于字符集的指定 ...