一开始出了点bug能看见排行榜,于是我看见我半个小时就A掉了前两题,信心场QAQ
T1字符串题就不说了qwq
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<algorithm> #define ll long long using namespace std; const int maxn=500010,inf=1e9; int n,m,x,y,z,tot; char c; int main() { int daxie=1; while((c=getchar())!=EOF) { if(('a'<=c&&c<='z')||('A'<=c&&c<='Z')) { if(daxie) { if('a'<=c&&c<='z')putchar(c-'a'+'A'); else putchar(c); daxie=0; } else { if('a'<=c&&c<='z')putchar(c); else putchar(c-'A'+'a'); } } else if(c=='.')daxie=1,putchar('.'); else putchar(' '); } return 0; }
T2直接贪心不断找出最大的数和他的下一个数,用双向链表维护一下前面和后面的数就好了
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<algorithm> #include<queue> #define ll long long using namespace std; const int maxn=500010,inf=1e9; struct poi{int pos,w;}; priority_queue<poi>q; bool operator<(poi a,poi b){return a.w<b.w;} int n,m,x,y,z,tot; int nxt[maxn],pre[maxn],a[maxn]; bool v[maxn]; void read(int &k) { int f=1;k=0;char c=getchar(); while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar(); while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar(); k*=f; } void del(int x) { nxt[pre[x]]=nxt[nxt[x]]; pre[nxt[nxt[x]]]=pre[x]; pre[x]=nxt[x]=pre[nxt[x]]=nxt[nxt[x]]=0; } int main() { read(n); for(int i=1;i<=n;i++)read(a[i]),pre[i]=i-1,nxt[i]=i+1,q.push((poi){i,a[i]}); for(int i=1;i<=n>>1;i++) { poi t=q.top();q.pop(); while(v[t.pos]||nxt[t.pos]>n)t=q.top(),q.pop(); printf("%d %d ",t.w,a[nxt[t.pos]]); v[nxt[t.pos]]=1;del(t.pos); } return 0; }
T3可以发现每行每列最多加两次,因为每隔2个数就有一个稳数...于是3^n枚举列的状态,算出每一行不加,加一个,加两个哪个优,每一行互不影响,于是每一行贪心地选一个最大的就好了
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<algorithm> #define ll long long using namespace std; const int maxn=20,inf=1e9; int n,m,x,y,z,ans; int mp[maxn][maxn],mi[maxn]; void read(int &k) { int f=1;k=0;char c=getchar(); while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar(); while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar(); k*=f; } int main() { read(n);read(m); for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)read(mp[i][j]); mi[0]=1;for(int i=1;i<=max(n,m);i++)mi[i]=mi[i-1]*3; for(int s=0;s<=mi[m];s++) { int now=0; for(int i=1;i<=n;i++) { int tmp1,tmp2,tmp3;tmp1=tmp2=tmp3=0; for(int j=1;j<=m;j++) if(s/mi[j-1]%3==1) { tmp1+=(mp[i][j]==2||mp[i][j]==5||mp[i][j]==8||mp[i][j]==11); tmp2+=(mp[i][j]==1||mp[i][j]==4||mp[i][j]==7||mp[i][j]==10); tmp3+=(mp[i][j]==0||mp[i][j]==3||mp[i][j]==6||mp[i][j]==9); } else if(s/mi[j-1]%3==0) { tmp1+=(mp[i][j]==3||mp[i][j]==6||mp[i][j]==9||mp[i][j]==12); tmp2+=(mp[i][j]==2||mp[i][j]==5||mp[i][j]==8||mp[i][j]==11); tmp3+=(mp[i][j]==1||mp[i][j]==4||mp[i][j]==7||mp[i][j]==10); } else if(s/mi[j-1]%3==2) { tmp1+=(mp[i][j]==1||mp[i][j]==4||mp[i][j]==7||mp[i][j]==10); tmp2+=(mp[i][j]==0||mp[i][j]==3||mp[i][j]==6||mp[i][j]==9); tmp3+=(mp[i][j]==-1||mp[i][j]==2||mp[i][j]==5||mp[i][j]==8); } now+=max(tmp1,max(tmp2,tmp3)); } ans=max(ans,now); } printf("%d ",ans); return 0; }