暑假集训cf50练之15
Posted walfy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了暑假集训cf50练之15相关的知识,希望对你有一定的参考价值。
Codeforces Round #370 (Div. 2)
A水,直接看样例找规律,数组开小导致wa了一发。。。
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define ull unsigned long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-12; const int N=100000+10,maxn=500+100,inf=0x3f3f3f; ll a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i=0;i<n;i++)cin>>a[i]; a[n]=0; for(int i=0;i<n;i++) { cout<<a[i]+a[i+1]<<" "; } cout<<endl; return 0; } /********************* *********************/
B记录udlr的数目,求解的过程出了问题wa了两发。。。
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define ull unsigned long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-12; const int N=100000+10,maxn=500+100,inf=0x3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin>>s; if(s.size()&1) { cout<<-1<<endl; return 0; } int u=0,d=0,l=0,r=0; for(int i=0;i<s.size();i++) { if(s[i]==‘U‘)u++; else if(s[i]==‘D‘)d++; else if(s[i]==‘L‘)l++; else if(s[i]==‘R‘)r++; } int ans=0; if((u+d)%2==1) { ans++; ans+=abs(u-d)/2; ans+=abs(l-r)/2; } else { ans+=abs(u-d)/2; ans+=abs(l-r)/2; } cout<<ans<<endl; return 0; } /********************* UUUU *********************/
C很水,直接暴力1a
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define ull unsigned long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-12; const int N=100000+10,maxn=500+100,inf=0x3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); int a,b; cin>>a>>b; int x=b,y=b,z=b,k=0; while(x<a&&y<a&&z<a){ int te=x+y+z-min(x,min(y,z)); if(x==min(x,min(y,z)))x=te-1; else if(y==min(x,min(y,z)))y=te-1; else z=te-1; k++; // cout<<x<<" "<<y<<" "<<z<<endl; } cout<<k+2<<endl; return 0; } /********************* *********************/
以上是关于暑假集训cf50练之15的主要内容,如果未能解决你的问题,请参考以下文章