//A #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m,k,p; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n>>m>>k>>p; res=0; for(int i=0;i<n;i++){ cin>>num; if(abs(num-p)%k!=0) continue; if(abs(num-p)>m*k) continue; res++; } cout<<res<<endl; } return 0; }
//B #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n; for(int i=0;i<n;i++) cin>>a[i],f[i]=a[i]; sort(f,f+n); for(int i=0;i<n;i++){ if(f[i]%2==0&&a[i]%2==0) continue; else if(f[i]%2!=0&&a[i]%2!=0) continue; else{ cout<<"NO"<<endl; goto nexts; } } cout<<"YES"<<endl; nexts:; } return 0; }
//c #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m,k; bool vis[N]; signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ cin>>n>>k; int num1=0,num2=0; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++){ if(a[i]==a[0]) num1++; if(num1>=k&&a[i]==a[n-1]) num2++; } if((num1>=k&&num2>=k)||(a[0]==a[n-1]&&num1>=k)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
//d //可以观察规律,当差分数组有两个数未出现,则第一个数组的合一定是序列的前缀和 //如果只有一个数没出现,则用序列的前缀和减去第一个数组的合就是那个剩下的数 #include <bits/stdc++.h> #define int long long using namespace std; const int N=1e6+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m,k,c[N]; map<int,int>vis; void solve() { vis.clear(); cin>>n; int num=0,ans=0,sum=(n*(n+1))/2,flag=1; for(int i=1;i<n;i++){ cin>>a[i]; c[i]=a[i]-a[i-1]; vis[c[i]]=1,num+=c[i]; } for(int i=1;i<=n;i++) if(!vis[i]) ans++; if((ans==2&&num==sum)||(ans==1&&((sum-num)>=1&&(sum-num)<=n))) cout<<"YES"<<endl; else cout<<"NO"<<endl; } signed main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>t; while(t--){ solve(); } return 0; }
//d //记忆化搜索 #include <bits/stdc++.h> #define int long long using namespace std; const int N=2e5+10,mod=1e9+7; string s; int n,t,a[N],f[N],res,num,ans,m,k; int e[N*2],ne[N*2],h[N*2],idx; bool vis[N]; void add(int a,int b){ e[idx]=b,ne[idx]=h[a],h[a]=idx++; } void dfs(int x) { if(vis[x]) return; vis[x]=true; int ans=0,cnt=0; for(int i=h[x];~i;i=ne[i]){ int j=e[i]; dfs(j); ans+=a[j],cnt++; } if(cnt) a[x]=min(a[x],ans); } void solve() { scanf("%lld%lld", &n, &m); memset(vis,false,sizeof vis); memset(h, -1, sizeof h); for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) cin>>k,a[k]=0; for(int i=1;i<=n;i++){ int x,y; scanf("%lld", &x); while(x--) scanf("%lld", &y),add(i,y); } for(int i=1;i<=n;i++){ dfs(i); printf("%lld ",a[i]); } printf("\n"); } signed main() { cin>>t; while(t--){ solve(); } return 0; }
标签:int,888,cin,long,vis,num,ans From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17609524.html