让你判断一个数列是不是这样一个数列:
一开始是严格上升
然后开始全都是一个数字
然后又开始严格下降
枚举中间全部相同的是哪个数字;
假设是i..j这一段
则看看1..i是不是严格上升,以及j+1..n是不是严格下降;
如果所有的这样的i..j都不满足则无解;
找到一组则有解;
0
找到最特殊的地方;
抓住问题的重点!
#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
",ans);
return 0;
}
/*
写完之后,明确每一步的作用
*/