#442 Div.2 AB &C. Slava and tanks 思维题
2017-10-30 12:34
309 查看
A. Alex and broken contest
大意:
求解一个字符串里是否有唯一特定的一些串,查询即可。
竟然被hack了。。substr函数写错了。
B. Nikita and string
大意:
一个只包含a和b的字符串,求最长的一个串,该串满足:
可以被分为三个部分,每个部分可以为空。
现在对一个串做删除操作(不改边顺序),求最长的串长度。
分析:
考虑两个分界点暴力枚举即可。
或者DP ,dp的思维不是很明显,其实就是前缀
C. Slava and tanks
大意:
有一个 1*n 的方格,每个方格内有若干个坦克,有两点生命值,每次被击中都会移动到相邻的格子。现在轰炸姬在上面轰炸,且看不到下方移动情况,求最少轰炸次数。
分析:
因为看不到具体的情况,肯定存在一种策略,因为每个坦克只能被击中两次,容易想到,先炸偶数,再炸奇数,再炸偶数即可。
具体实现:
PS.连续两次 C题比B题水 而且hack点好多
大意:
求解一个字符串里是否有唯一特定的一些串,查询即可。
竟然被hack了。。substr函数写错了。
string substr (size_t pos = 0, size_t len = npos) const; //第一个参数为起始位置,第二个参数为长度
B. Nikita and string
大意:
一个只包含a和b的字符串,求最长的一个串,该串满足:
可以被分为三个部分,每个部分可以为空。
现在对一个串做删除操作(不改边顺序),求最长的串长度。
分析:
考虑两个分界点暴力枚举即可。
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int,int> pii; #define mem(s,t) memset(s,t,sizeof(s)) #define D(v) cout<<#v<<" "<<v<<endl #define inf 0x3f3f3f3f #define pb push_back //#define LOCAL const int mod=1e9+7; const int MAXN =3e5+10; int a[MAXN],b[MAXN]; int main() { #ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif string s; cin>>s; mem(a,0); mem(b,0); int ret=0,l1=0,l2=0; if(s.size()<=3 && s!="bab"){ cout<<s.size()<<endl; return 0; } if(s=="bab"){ cout<<2<<endl; return 0; } if(s[0]=='a') a[0]=1,b[0]=0; else b[0]=1,a[0]=0; for(int i=1;i<s.size();i++){ if(s[i]=='a') a[i]=a[i-1]+1,b[i]=b[i-1]; else if(s[i]=='b') b[i]=b[i-1]+1,a[i]=a[i-1]; else a[i]=a[i-1],b[i]=b[i-1]; } int ans=0; for(int i=0;i<s.size();i++){ for(int j=i;j<s.size();j++){ int l1=0,l2=0,l3=0; if(i) l1=a[i-1]; else l1=0; if(i) l2=b[j]-b[i-1]; else l2=b[j]; if(j) l3=a[s.size()-1]-a[j-1]; else l3=a[s.size()-1]; ans=max(ans,l1+l2+l3); } } cout<<ans<<endl; return 0; }
或者DP ,dp的思维不是很明显,其实就是前缀
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int,int> pii; #define mem(s,t) memset(s,t,sizeof(s)) #define D(v) cout<<#v<<" "<<v<<endl #define inf 0x3f3f3f3f #define pb push_back //#define LOCAL const int mod=1e9+7; const int MAXN =3e5+10; int dp[3][MAXN]; int main() { #ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif string s; cin>>s; mem(dp,0); int n=s.length(); for(int i=1;i<=n;i++){ if(s[i-1]=='a'){ dp[0][i]=dp[0][i-1]+1; dp[1][i]=dp[1][i-1]; dp[2][i]=max(dp[1][i-1]+1,dp[2][i-1]+1); }else { dp[0][i]=dp[0][i-1]; dp[1][i]=max(dp[1][i-1]+1,dp[0][i-1]+1); dp[2][i]=dp[2][i-1]; } } printf("%d\n",max({dp[0] ,dp[1] ,dp[2] })); return 0; }
C. Slava and tanks
大意:
有一个 1*n 的方格,每个方格内有若干个坦克,有两点生命值,每次被击中都会移动到相邻的格子。现在轰炸姬在上面轰炸,且看不到下方移动情况,求最少轰炸次数。
分析:
因为看不到具体的情况,肯定存在一种策略,因为每个坦克只能被击中两次,容易想到,先炸偶数,再炸奇数,再炸偶数即可。
具体实现:
#include <bits/stdc++.h> using n 1031e amespace std; typedef long long ll; typedef pair <int,int> pii; #define mem(s,t) memset(s,t,sizeof(s)) #define D(v) cout<<#v<<" "<<v<<endl #define inf 0x3f3f3f3f #define pb push_back //#define LOCAL const int mod=1e9+7; const int MAXN =3e5+10; int a[MAXN]; int main() { #ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int n; scanf("%d",&n); int f=1; printf("%d\n",n+n/2); for(int i=2;i<=n;i+=2){ if(f) f=0,printf("%d",i); else printf(" %d",i); } for(int i=1;i<=n;i+=2){ printf(" %d",i); } for(int i=2;i<=n;i+=2){ printf(" %d",i); } puts(""); return 0; }
PS.连续两次 C题比B题水 而且hack点好多
相关文章推荐
- Codeforces 877(442 Div.2) C. Slava and tanks
- 【Codeforces Round #442 (Div. 2) C】Slava and tanks
- Codeforces #371(Div.2)C.Sonya and Queries【map应用】【思维】
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery && Codeforces 360 A 详解(思维+维护理论值)
- Codeforces Round #442 (Div. 2) C - Slava and tanks
- Codeforces Round #419 (Div. 2)-贪心&思维-C. Karen and Game
- Codeforces #337 (Div.2)B.Vika and Squares【思维】水题
- Codeforces #370 (Div.2) B. Memory and Trident【思维】
- CodeChef:Desik And Divisors(数学 & 二分 & 思维)
- hpu暑假训练C - Patrick and Shopping 【思维】&&【水题】
- codeforces - 877C - Slava and tanks 【找规律呀找规律】
- Codeforces Round 421 Div.2 D. Mister B and PR Shifts 思维 乱搞
- #416 Div.2 B. Vladik and Complicated Book - 排序&技巧
- CF551D:GukiZ and Binary Operations(矩阵 & 思维)
- codeforces877C(div2)Slava and tanks(脑洞)
- 【前缀和 && 思维转换】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)Molly's Chemicals
- Codeforces 877 C Slava and tanks
- Codeforces Round #442 (Div. 2) C. Slava and tanks 【找规律】
- codeforces #354 div.2 C &&676C Vasya and String
- Codeforces Round 261 Div.2 D Pashmak and Parmida&#39;s problem --树状数组