好久不曾看星空,愿抬头再望,你我眼里尽是星辰大海
img
Educational Codeforces Round
90
A. Donut Shops
解题报告:
显然如果a*b<c,那么肯定是买单的划算啊.
如果等于,那么单的买一个可以,但盒装肯定不行
如果a>=c,那么永远不可能,盒装肯定便宜
a*b>c,那么盒装可以买一盒的,因为上面判断过了保证a<c,然后那个买b盒就行。
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
| #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; void TOtoro() { int a,b,c; cin>>a>>b>>c; if(a*b<c) { cout<<1<<" "<<-1<<'\n'; } else if(a>=c) { cout<<-1<<' '<<b<<'\n'; } else if(a*b>c) { cout<<1<<' '<<b<<'\n'; } else { cout<<1<<" "<<-1<<'\n'; } } signed main() { int t; cin>>t; while(t--) { TOtoro(); } return 0; }
|
B. 01 Game
计算能消去多少个,奇数显然赢了,偶数显然输了
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
| #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; void Totoro() { string s; cin>>s; int n=s.length(); s=" "+s; int ans1=0; int ans2 =0; rep(i,1,n) { if(s[i]=='1') { ans1++; } else { ans2++; } } ans1=min(ans1,ans2); if(ans1&1) { cout<<"DA"<<'\n'; } else { cout<<"NET"<<'\n'; } } signed main() { int t; cin>>t; while(t--) { Totoro(); } return 0; }
|
C. Pluses and Minuses
题意: 就是题中所给代码最后得到 res 的值 .
翻译一下就比如一个横板2D闯关游戏 ,一开始血量 cur = 0
,每一格对应一个字符 ,每次碰到 '-' 则血量-- ,'+' 则血量++ ,若血量cur <
0 则从头再来且初始血量 +1 直至通关,求最后一共走过多少格 .
解: 求前缀和 ,记 '-' 为 -1 ,'+' 为 +1 ,因为前缀和是连续的
,所以每次记录血量为 0 时找前缀和第一次为 -1 的下标
,记录血量为 1 是第一次为 -2 的下标...
最后下标值相加即可 .
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
| #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; void Totoro() { string s; cin>>s; int ans=0; int f=-1; int n=s.length(); s=" "+s; int sum=0; rep(i,1,n) { if(s[i]=='+') { sum++; } else { sum--; } if(sum==f) { ans+=i; f--; } } cout<<ans+n<<'\n'; } signed main() { int t; cin>>t; while(t--) { Totoro(); } return 0; }
|
D. Maximum Sum on Even
Positions
解题报告:
由于变化肯定是前后,直接用最大子段和的思想就行。
注意前后有两种,一开始写得很麻烦,不过也是最大子段和的思路,代码还是不够简洁啊。
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
| #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; int a[N]; int sum_[N];
void Totoro() { int n; cin>>n; int sum=0; rep(i,1,n) { cin>>a[i]; if(i&1) { sum+=a[i]; }
} int res=0; int ans=0; for(int i=1;i<=n-1;i+=2) { res+=(a[i+1]-a[i]); if(res<0) { res=0; } ans=max(ans,res); } res=0; for(int i=3;i<=n;i+=2) {
res+=(a[i-1]-a[i]); if(res<0) { res=0; } ans=max(ans,res); } cout<<sum+ans<<'\n';
} signed main() { int t; cin>>t; while(t--) { Totoro(); } return 0; }
|