标签:nbsp vector 存在 class 方式 close 枚举 cond cout
#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<set> #include<stack> #include<map> #define pb push_back #define mp make_pair #define fi first #define se second #define mul_mod(a,b,c) a=(a*b)%mod #define add_mod(a,b,c) a=(a+b)%mod using namespace std; typedef long long ll; const int maxn=2e5+10; const int maxm=5e5+10; const int inf=0x3f3f3f3f; int q; int n; int main() { scanf("%d",&q); while(q--){ scanf("%d",&n); for(int i=1;i<=n;i++) cout<<1<<" "; cout<<endl; } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<set> #include<stack> #include<map> #define pb push_back #define mp make_pair #define fi first #define se second #define mul_mod(a,b,c) a=(a*b)%mod #define add_mod(a,b,c) a=(a+b)%mod using namespace std; typedef long long ll; const int maxn=2e5+10; const int maxm=5e5+10; const int inf=0x3f3f3f3f; int q,n; int main() { scanf("%d",&q); while(q--){ scanf("%d",&n); map<int,int> ma; int flag=0; for(int i=1;i<=n;i++){ int t; scanf("%d",&t); if(ma[t]) flag=1; else ma[t]=1; } if(flag) puts("YES"); else puts("NO"); } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<set> #include<stack> #include<map> #define pb push_back #define mp make_pair #define fi first #define se second #define mul_mod(a,b,c) a=(a*b)%mod #define add_mod(a,b,c) a=(a+b)%mod using namespace std; typedef long long ll; const int maxn=1e2+10; const int maxm=5e5+10; const int inf=0x3f3f3f3f; int q,n,m,t; int main() { scanf("%d",&q); while(q--){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&t); if((i+j)%2==t%2) t++; cout<<t<<" "; } cout<<endl; } } return 0; }
a1 | a2 | a3 | a4 | a5 | a6 | a7 |
p1 | p1 | p1 | a4 | a5 | a6 | a7 |
p1 | p1 | p2 | p2 | p2 | a6 | a7 |
p1 | p1 | p2 | p2 | p3 | p3 | p3 |
#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<set> #include<stack> #include<map> #define pb push_back #define mp make_pair #define fi first #define se second #define mul_mod(a,b,c) a=(a*b)%mod #define add_mod(a,b,c) a=(a+b)%mod using namespace std; typedef long long ll; const int maxn=1e5+10; const int maxm=5e5+10; const int inf=0x3f3f3f3f; int n; int a[maxn]; void solveAdd(int n){ puts("YES"); printf("%d\n",n-2); for(int i=1;i<n;i+=2) printf("%d %d %d\n",i,i+1,i+2); for(int i=1;i<n-2;i+=2) printf("%d %d %d\n",i,i+1,n); } void solveEven(int n){ int sum=0; for(int i=1;i<=n;i++) sum^=a[i]; if(sum){ puts("NO"); return; } solveAdd(n-1); } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); if(n%2) solveAdd(n); else solveEven(n); return 0; }
题意:给定一个长度为n(3<=n<=2e5)的数组,问存在多少个长度至少为3区间[l,r],满足a[l]^a[r]=(a[l+1]+a[l+2]+...+a[r-1])
#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<set> #include<stack> #include<map> #define pb push_back #define mp make_pair #define fi first #define se second #define mul_mod(a,b,c) a=(a*b)%mod #define add_mod(a,b,c) a=(a+b)%mod using namespace std; typedef long long ll; const int maxn=2e5+10; const int maxm=5e5+10; const int inf=0x3f3f3f3f; int n; int a[maxn]; set<ll> se; int getMax(int x){ for(int i=1<<30;i;i>>=1){ if(x&i) return i<<1; } } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int l=1;l<n-1;l++){ ll sum=a[l+1]; int k=getMax(a[l]); for(int r=l+2;r<=n&&sum<=k;r++){ if((a[l]^a[r])==sum) se.insert((ll)l*maxn+r); sum+=a[r]; } } for(int r=n;r>=3;r--){ ll sum=a[r-1]; int k=getMax(a[r]); for(int l=r-2;l>=1&&sum<=k;l--){ if((a[l]^a[r])==sum) se.insert((ll)l*maxn+r); sum+=a[l]; } } cout<<se.size()<<endl; return 0; }
Codeforces Round #682 (Div. 2) 题解(A-E)
标签:nbsp vector 存在 class 方式 close 枚举 cond cout
原文地址:https://www.cnblogs.com/Momo-zzz/p/13992099.html