赞
踩
直接猜的。
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=110; int a[N]; void solve() { int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; int res=1; int ans=0; for(int i=2;i<=n;i++) { if(a[i]==a[i-1]) { res++; } else { ans=max(ans,res); res=1; } } ans=max(ans,res); cout<<ans<<endl; } int main() { int t; t=1; cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e4 + 10; ll a[N]; bool get_s(ll x, ll d) { bool flag = true; string s = to_string(x); for (int i = 0; i < s.length(); i++) { if (s[i] - '0' == d) { flag = false; break; } } if (!flag) return true; else return false; } void solve() { ll q, d; cin >> q >> d; for (int i = 1; i <= q; i++) cin >> a[i]; ll dp[11] = {-1}; for (int i = 1; i <= 9; i++) dp[i] = (d * i) % 10; for (int i = 1; i <= q; i++) { if (get_s(a[i], d)) { cout << "Yes" << endl; } else { ll x = a[i] % 10; bool flag = false; if (a[i] % d == 0) { cout << "Yes" << endl; continue; } if (a[i] >= d * 10) { flag = true; cout << "Yes" << endl; continue; } for (int j = 1; j <= 9; j++) { if (x == dp[j]) { if (a[i] >= j * d) { flag = true; cout << "Yes" << endl; break; } else continue; } } if (!flag) { cout << "No" << endl; } } } } int main() { int t; t = 1; cin >> t; while (t--) { solve(); } }
某个大佬的,侵权删除。
题意
思路
因为2*x-y=x+x-y,相当于加上和任意数的差,所以只需要判断一下数组中的任意一个是否能够加上多少称为k。加上多少的这个数就是所有数差的gcd。
代码
#include<bits/stdc++.h> using namespace std; #define ll long long ll a[202020]; int main() { ll k,n,t,T=1; cin>>T; while(T--) { cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; ll g=abs(a[1]-a[2]); for(int i=3;i<=n;i++) g=__gcd(g,abs(a[i]-a[i-1])); if((k-a[1])%g==0) cout<<"YES"<<endl; else cout<<"NO"<<endl; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。