#include<iostream>#include<cstring>#include<algorithm>usingnamespace std;#defineintlonglongconstint N =200010, mod =1e18;signedmain(){int a, b; cin >> a >> b;if(((a + b)&1)&&__gcd(a, b)==1) cout <<"Yes"<<'\n';else cout <<"No"<<'\n';}
B 宝石 — map优化
#include<iostream>#include<algorithm>#include<unordered_map>usingnamespace std;#defineintlonglongconstint N =2010;int a[N];signedmain(){int n; cin >> n;for(int i =0; i < n; i ++) cin >> a[i];
unordered_map<int,int>mp;for(int i =0; i < n; i ++)for(int j = i; j < n; j ++)
mp[a[i]* a[j]]= i;int res =0;for(int i =0; i < n; i ++)for(int j = i +1; j < n; j ++)if(!a[j]&&!a[i]|| a[j]&& a[i]% a[j]==0&& mp[a[i]/ a[j]]> i){
res ++;break;}
cout << res <<'\n';}
C 斩龙 — 模拟
#include<iostream>usingnamespace std;#defineintlonglongsignedmain(){int a1, a2, a3, h1, h2, h3, k, x;
cin >> a1 >> h1 >> a2 >> h2 >> x;
cin >> k >> a3 >> h3;int res =0;int sum = x - k;int cnt2 =(h2 + a1 -1)/ a1;if(sum >0){
res += cnt2 * sum;
h1 -=(cnt2 -1)* sum * a2;}
k =min(x, k);
res += cnt2 * k;
h1 -= a3 * cnt2 * k;
h1 -= a2 *(cnt2 -1)* k;int cnt1 =(h3 + a1 -1)/ a1;
res += cnt1;
h1 -=(cnt1 -1)* a3;if(h1 <0) cout <<"No Franxx!\n";else cout << res <<'\n';}
D 数对 ---- 树状数组 + 推导
#include<iostream>#include<cstring>#include<algorithm>#include<vector>usingnamespace std;#defineintlonglongconstint N =400010;int n, x, y;int tr[N], s[N];
vector<int> nums;intfind(int x){returnlower_bound(nums.begin(), nums.end(),x)- nums.begin()+1;}intlowbit(int x){return x &-x;}voidadd(int x,int v){for(int i = x; i <=2* n +2; i +=lowbit(i)) tr[i]+= v;}intquery(int x){int res =0;for(int i = x; i; i -=lowbit(i)) res += tr[i];return res;}signedmain(){
cin >> n >> x >> y;for(int i =1; i <= n; i ++){
cin >> s[i];
s[i]-= y;
s[i]+= s[i -1];}for(int i =0; i <= n; i ++){
nums.push_back(s[i]);
nums.push_back(s[i]- x -1);}sort(nums.begin(),nums.end());
nums.erase(unique(nums.begin(), nums.end()), nums.end());int res =0;for(int i =0; i <= n; i ++){
res +=query(2* n +2)-query(find(s[i]- x -1));add(find(s[i]),1);}
cout << res <<'\n';}
E 双星 — 数学
#include<iostream>#include<cstring>#include<algorithm>#include<vector>#include<cmath>usingnamespace std;#defineintlonglongconstdouble pi =acos(-1);structcircle{int x, y, r;double a, b;voidinput(){ cin >> x >> y >> r;}voidcal_ab(){// 计算圆所占的极角序区间 [a, b]double mid =atan2(y, x), rad =asin(r /sqrt(x * x + y * y));
a = mid - rad, b = mid + rad;}};boolcheck_intersected(double a,double b,double c,double d){// 判断两个区间 [a, b], [c, d] 是否有交集return c < b && a < d;}boolcheck_seeable(double a,double b,double c,double d){// 判断 [c, d] 在 [a, b] 的遮挡下是否能被看到;是返回 1,否则返回 0return c < a || d > b;}
circle c1, c2;signedmain(){
c1.input(), c2.input();
c1.cal_ab(), c2.cal_ab();if(c1.x * c1.x + c1.y * c1.y > c2.x * c2.x + c2.y * c2.y)swap(c1, c2);// 靠近原点的圆作为 c1for(double dt :{0.0,-2* pi,2* pi}){double a = c1.a, b = c1.b, c = c2.a + dt, d = c2.b + dt;if(check_intersected(a, b, c, d)){if(check_seeable(a, b, c, d)) cout <<"Yes";else cout <<"No";return0;}}
cout <<"Yes";}
F 手办 — 签到
#include<iostream>#include<vector>usingnamespace std;#defineintlonglongsignedmain(){
vector<int>vec;for(int i =1; i <=1000; i ++) vec.push_back(i*i*i);int T; cin >> T;while(T --){int n; cin >> n;int res =0;for(int i =1; i <=1000; i ++)if(n % vec[i -1]==0) res ++;
cout << res <<'\n';}}
G 无限 — dp
#include<iostream>#include<cstring>#include<algorithm>#include<queue>usingnamespace std;#defineintlonglongconstint N =2000010, mod =998244353;int f[N];signedmain(){int n; cin >> n;
f[1]=1;for(int i =2; i <= n; i ++) f[i]=(f[i -1]+ f[i -2])% mod;int res =0;for(int i =1; i <= n; i ++) res =(res + f[i])% mod;
cout << res <<'\n';}
H 0和1 — 贪心
#include<iostream>#include<cstring>#include<algorithm>#include<queue>usingnamespace std;#defineintlonglongconstint N =200010, mod =1e18;
string s;intcal(char op){
vector<pair<int,int>> vec;int res =0;for(int i =0; i < s.size(); i ++){if(s[i]== op){int j = i;while(s[j]== s[i]) j ++;
j --;if(vec.size()&& j - i +1+ vec.back().second - vec.back().first +1>=3&& vec.back().second +2== i){
res ++;
vec.back().second = j;}else vec.push_back({i, j});
i = j;}}for(auto[l, r]: vec)if(r - l +1>=2) res +=2;else res ++;return res;}signedmain(){
cin >> s;
cout <<min(cal('0'),cal('1'))<<'\n';}
I 22数 — 数位dp / dfs暴搜
数位dp
#include<iostream>#include<cstring>#include<algorithm>#include<queue>usingnamespace std;#defineintlonglongconstint N =200010, mod =1e18;int n;int f[11][11][110];// 前 i 位 第 i 位为 j,数字之和 为 k的 数的个数// f[i][j][k] += f[i - 1][u][k - j];voidinit(){for(int i =0; i <=9; i ++) f[1][i][i]=1;for(int i =2; i <=10; i ++)for(int j =0; j <=9; j ++)for(int k = j; k <=90; k ++)for(int u =0; u <=9; u ++)
f[i][j][k]+= f[i -1][u][k - j];}intcal(int n){
vector<int> nums;while(n) nums.push_back(n %10), n /=10;int res =0, sum =0, len = nums.size();for(int i = nums.size()-1; i >=0; i --){int x = nums[i];for(int j = i == nums.size()-1; j < x; j ++)
res += f[i +1][j][len *2- sum];
sum += x;if(sum > len *2)break;if(!i && sum == len *2) res ++;}for(int i =1; i < len; i ++)for(int j =1; j <=9; j ++)
res += f[i][j][2* i];return res;}signedmain(){init();
cin >> n;
cout <<cal(n)<<'\n';}
暴搜
#include<iostream>usingnamespace std;#defineintlonglongint n, res =0;voiddfs(int x,int sum,int cnt){if(x > n || sum >20)return;if(cnt && sum == cnt *2) res ++;for(int i =0; i <=9; i ++){int y = x *10+ i;if(y)dfs(y, sum + i, cnt +1);}}signedmain(){
cin >> n;dfs(0,0,0);
cout << res <<'\n';}
J 签到 — 签到
#include<iostream>#include<set>usingnamespace std;#defineintlonglongconstint N =1010;int a[N];signedmain(){int n; cin >> n;for(int i =0; i < n; i ++) cin >> a[i];
set<int> S;for(int i =0; i < n; i ++)for(int j =0; j < n; j ++)
S.insert(a[i]+ a[j]);for(int i =0; i < n; i ++)for(int j =0; j < n; j ++)if(S.count(a[i]- a[j])){
cout <<"Yes"<<'\n';return0;}
cout <<"No"<<'\n';}
#include<iostream>#include<cstring>usingnamespace std;signedmain(){
string s; cin >> s;int res =0;if(s.size()<3){
cout <<0<<'\n';return0;}for(int i =0; i +2< s.size(); i ++)if(s[i]=='H'&& s[i +1]=='P'&& s[i +2]=='U') res ++;
cout << res <<'\n';}