【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两种颜色的格子; 让你在这个格子 ...
随机推荐
- NUTCH2.3 hadoop2.7.1 hbase1.0.1.1 solr5.2.1部署(一)
Precondition: hadoop 2.7.1 Nutch 2.3 hbase 1.0.1.1 / hbase 0.98.13 solr 4.8.1 Linux version 3.16. ...
- Import Example Dataset
Overview The examples in this guide use the restaurants collection in the test database. The followi ...
- 25.不改变原生数据的STL algorithm
通过仿函数for_each操作 vector<,,,, }; list<double> db{ 1.1,2.2,3.3,4.4,5.5 }; //循环算法,算法的泛型 print p ...
- dom4j组装xml 以及解析xml
dom4j组装xml 以及解析xml: 1.下载dom4j的jar包,地址:https://dom4j.github.io/ 2.java代码: package test; import java.i ...
- Intellij格式化java和xml
使用Intellij的这段时间,一直在寻找一些技巧,不断提高对它的熟练度.接下来告诉大家一个小秘密,带大家体验一下Intellij半自动格式化代码的快感.那要使用这个功能还得安装一个插件--Eclip ...
- 关于docker部署javaweb应用的问题
我做了两个镜像,一个mysql,一个tomcat.建完mysql容器之后,在建tomcat的时候用--link把他们链接起来了进tomcat的容器里面 /etc/hosts 也发现了mysql的ip但 ...
- 《剑指offer》旋转数组的最小数字
一.题目描述 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 二.输入描述 输入一个递增排序的数组的一个旋转 三.输出描述 输出旋转数组的最小元素 例如: 例如数组{3,4,5,1 ...
- CMake入门之创建一个基于PCL的最小工程
最近在学习PCL,借助Cmake可省去繁琐的添加包含目录和依赖库操作. 一个典型的CMakeLists.txt内容通常为: cmake_minimum_required(VERSION 2.6 FAT ...
- git提交的规范
- centOS7下 安装nodejs+nginx+mongodb+pm2部署vue项目
一.购买服务器并远程连接 1.购买服务器和域名 可以选择阿里云或者是其他的厂商的服务器.然后会获得服务器ip地址,用户名和密码. 购买域名,将域名绑定到ip地址上. 2.下载xshell,winscp ...