Codeforces Round #685 (Div. 2)
Codeforces Round #685 (Div. 2)
可以除掉很大的因数,答案只会是0,1,2,3
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define ls u<<1 #define rs u<<1|1 #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second using namespace std; typedef long long ll; typedef double db; typedef pair<int, int > PII; priority_queue< PII, vector<PII>, greater<PII> > que; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; ll n, x; inline ll read() { char c=getchar();ll x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();} return x*f; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif n = read(); while (n--) { x = read(); if (x == 1) puts("0"); else if (x == 2) puts("1"); else if (x % 2 == 0 || x == 3) puts("2"); else puts("3"); } // #ifndef ONLINE_JUDGE // system("pause"); // #endif }
暴力判断两边l、r两边的情况
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define ls u<<1 #define rs u<<1|1 #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second using namespace std; typedef long long ll; typedef double db; typedef pair<int, int > PII; priority_queue< PII, vector<PII>, greater<PII> > que; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; int _, n, q; char s[N]; inline ll read() { char c=getchar();ll x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();} return x*f; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif _ = read(); while (_--) { n = read(); q = read(); scanf("%s", s + 1); while (q--) { int l, r; bool flag = 0; l = read(); r = read(); for (int i = 1; i < l; ++i) { if (s[i] == s[l]) { flag = 1; break; } } for (int i = r + 1; i <= n; ++i) { if (s[i] == s[r]) { flag = 1; break; } } if (flag) puts("YES"); else puts("NO"); } } // #ifndef ONLINE_JUDGE // system("pause"); // #endif }
开两个桶,一直把状态往后移,判断下位置是否合法即可
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define ls u<<1 #define rs u<<1|1 #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second using namespace std; typedef long long ll; typedef double db; typedef pair<int, int > PII; priority_queue< PII, vector<PII>, greater<PII> > que; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const int N = 2e6 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; int _, n, k; char s[N], t[N]; int a[30], b[30]; inline ll read() { char c=getchar();ll x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();} return x*f; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif _ = read(); while (_--) { mm(a, 0); mm(b, 0); n = read(); k = read(); scanf("%s", s + 1); scanf("%s", t + 1); rep(i, 1, n) a[s[i] - 'a' + 1]++; rep(i, 1, n) b[t[i] - 'a' + 1]++; bool flag = 0; rep(i, 1, 26) { if (a[i] < b[i]) { flag = 1; break; } a[i] -= b[i]; b[i] = 0; if (a[i] % k) { flag = 1; break; } a[i + 1] += a[i]; } if (a[26] != b[26]) { flag = 1; } if (flag) puts("NO"); else puts("YES"); } // #ifndef ONLINE_JUDGE // system("pause"); // #endif }
可以发现对于后手来说最优解一定是对照先手走对角线,只需判断 d - floor(d /(sqrt(2)*k))和 k 的大小即可
会有精度问题所以不能直接比较,可以通过便利来求出最终的区间来规避精度问题
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <stack> #include <sstream> #include <set> // #pragma GCC optimize(2) //#define int long long #define ls u<<1 #define rs u<<1|1 #define rep(i,a,n) for(int i=a;i<=n;i++) #define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define mm(i,v) memset(i,v,sizeof i); #define mp(a, b) make_pair(a, b) #define pi acos(-1) #define fi first #define se second using namespace std; typedef long long ll; typedef double db; typedef pair<int, int > PII; priority_queue< PII, vector<PII>, greater<PII> > que; stringstream ssin; // ssin << string while ( ssin >> int) const ll LINF = 0x7fffffffffffffffll; const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f; ll _, d, k; int sg[N]; inline ll read() { char c=getchar();ll x=0,f=1; while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();} return x*f; } int main() { _ = read(); while (_--) { d = read(); k = read(); ll t = 0; while (t*k*t*k + t*k*t*k <= d*d) ++t; --t; ++t; --t; ll u = floor(sqrt(d*d - t*t*k*k) / k) - t; if (u & 1) puts("Ashish"); else puts("Utkarsh"); // mm(sg, 0); // ll r = d / k; // for (int i = r; i >= 0; --i) { // ll h = d * d - i * i * k * k; // double hh = sqrt(h); // h = floor(hh); // ll tp = h / k; // if (i == r) { // cout << h << '\n'; // cout << hh << '\n'; // cout << tp << '\n'; // puts(""); // } // if (i == r) { // if (tp & 1) sg[i] = 1; // else sg[i] = 2; // } else { // if (sg[i + 1] == 2) sg[i] = 1; // else { // sg[i] = 2; // } // } // } // // cout << sg[2] << '\n'; // if (sg[0] == 2) puts("Utkarsh"); // else puts("Ashish"); } return 0; }