img
AtCoder Beginner Contest 349
A
直接累加输出负数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include<bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,a,n) for(int i=a;i<=n;i++) #define frep(i,a,n) for(int i=a;i>=n;i--) #define int long long #define PII pair<int,int> #define lowbit(x) (x&(-x)) const int mod=1e9+7; const double pai=acos(-1.0); #define ios ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); #define LF(x) fixed<<setprecision(x) const int N=1e6+100; #define CY cout<<"YES<<'\n" #define CN cout<<"NO"<<'\n' int a[N]; void Totoro() { int n; cin>>n; int sum=0; rep(i,1,n) { cin>>a[i]; sum+=a[i]; } cout<<-sum<<'\n'; } signed main() { int t=1; while(t--) { Totoro(); } return 0; }
|
B
两个map,先记录次数,再记录次数出现的字母,在判断
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #include<bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,a,n) for(int i=a;i<=n;i++) #define frep(i,a,n) for(int i=a;i>=n;i--) #define int long long #define PII pair<int,int> #define lowbit(x) (x&(-x)) const int mod=1e9+7; const double pai=acos(-1.0); #define ios ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); #define LF(x) fixed<<setprecision(x) const int N=1e6+100; #define CY cout<<"YES<<'\n" #define CN cout<<"NO"<<'\n' int a[N]; void Totoro() { string s; cin>>s; int n=s.length(); s=" "+s; map<char,int>a; rep(i,1,n) { a[s[i]]++; } map<int,char>b; for(auto &[x,y]:a) { b[y]++; } for(auto &[x,y]:b) { if(y!=2&&y!=0) { cout<<"No"; return ; } } cout<<"Yes";
} signed main() { int t=1; while(t--) { Totoro(); } return 0; }
|
C
本题有点抽象,因为没看到后缀爆wa,需要好好擦眼睛了。
只需要对有x和没有x进行讨论,主要就是看有没有出现,记录一下即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| #include<bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,a,n) for(int i=a;i<=n;i++) #define frep(i,a,n) for(int i=a;i>=n;i--) #define int long long #define PII pair<int,int> #define lowbit(x) (x&(-x)) const int mod=1e9+7; const double pai=acos(-1.0); #define ios ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); #define LF(x) fixed<<setprecision(x) const int N=1e6+100; #define CY cout<<"YES<<'\n" #define CN cout<<"NO"<<'\n' void Totoro() { string s; string x; cin>>s>>x;
int n=s.length()-1; int b=x.length()-1;
x[0]+='a'-'A'; x[1]+='a'-'A'; x[2]+='a'-'A'; if(x[2]=='x') { map<char,int>mp; int c=-1,d=-1; bool flag=1; bool f=1; rep(i,0,n) { if(s[i]==x[0]&&flag) { c=i; flag=0; } if(s[i]==x[1]) { d=i; } } if(c!=-1&&d!=-1&&c<d) { cout<<"Yes"; } else { cout<<"No"; } } else { int c=-1,d=-1; bool flag=1; bool f=0; rep(i,0,n) { if(s[i]==x[0]&&flag) { c=i; flag=0; } if(s[i]==x[2]) { d=i; } } if(c!=-1&&d!=-1) { rep(i,c+1,d-1) { if(s[i]==x[1]) { f=1; } } } if(f) { cout<<"Yes"; } else { cout<<"No"; } }
} signed main() { int t=1; while(t--) { Totoro(); } return 0; }
|
D
这个条件决定了取模等于0这一特判,从高到低位的贪心的特判从此而来
\(S(2^i j, 2^i (j+1))\)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include<bits/stdc++.h> using namespace std; using ll=long long; #define rep(i,a,n) for(int i=a;i<=n;i++) #define frep(i,a,n) for(int i=a;i>=n;i--) #define int long long #define PII pair<int,int> #define lowbit(x) (x&(-x)) const int mod=1e9+7; const double pai=acos(-1.0); #define ios ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); #define LF(x) fixed<<setprecision(x) const int N=1e6+100; #define CY cout<<"YES<<'\n" #define CN cout<<"NO"<<'\n' int a[N]; void Totoro() { int l,r; cin>>l>>r; vector<ll>ans; while(l<r) { ll nowl=0; for(int i=60;i>=0;i--) { if(l%(1ll<<i)==0ll&&l+(1ll<<i)<=r) { nowl=(l+(1ll<<i)); break; } } ans.push_back(l); ans.push_back(nowl); l=nowl; } cout<<ans.size()/2<<'\n'; for(int i=0;i<ans.size();i+=2) { cout<<ans[i]<<" "<<ans[i+1]<<'\n'; } } signed main() { int t=1; while(t--) { Totoro(); } return 0; }
|