一开始出了点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=,inf=1e9;
int n,m,x,y,z,tot;
char c;
int main()
{
int daxie=;
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=;
}
else
{
if('a'<=c&&c<='z')putchar(c);
else putchar(c-'A'+'a');
}
}
else if(c=='.')daxie=,putchar('.');
else putchar(' ');
}
return ;
}
T2直接贪心不断找出最大的数和他的下一个数,用双向链表维护一下前面和后面的数就好了
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
const int maxn=,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=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',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]]=;
}
int main()
{
read(n);
for(int i=;i<=n;i++)read(a[i]),pre[i]=i-,nxt[i]=i+,q.push((poi){i,a[i]});
for(int i=;i<=n>>;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]]=;del(t.pos);
}
return ;
}
T3可以发现每行每列最多加两次,因为每隔2个数就有一个稳数...于是3^n枚举列的状态,算出每一行不加,加一个,加两个哪个优,每一行互不影响,于是每一行贪心地选一个最大的就好了
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=,inf=1e9;
int n,m,x,y,z,ans;
int mp[maxn][maxn],mi[maxn];
void read(int &k)
{
int f=;k=;char c=getchar();
while(c<''||c>'')c=='-'&&(f=-),c=getchar();
while(c<=''&&c>='')k=k*+c-'',c=getchar();
k*=f;
}
int main()
{
read(n);read(m);
for(int i=;i<=n;i++)for(int j=;j<=m;j++)read(mp[i][j]);
mi[]=;for(int i=;i<=max(n,m);i++)mi[i]=mi[i-]*;
for(int s=;s<=mi[m];s++)
{
int now=;
for(int i=;i<=n;i++)
{
int tmp1,tmp2,tmp3;tmp1=tmp2=tmp3=;
for(int j=;j<=m;j++)
if(s/mi[j-]%==)
{
tmp1+=(mp[i][j]==||mp[i][j]==||mp[i][j]==||mp[i][j]==);
tmp2+=(mp[i][j]==||mp[i][j]==||mp[i][j]==||mp[i][j]==);
tmp3+=(mp[i][j]==||mp[i][j]==||mp[i][j]==||mp[i][j]==);
}
else if(s/mi[j-]%==)
{
tmp1+=(mp[i][j]==||mp[i][j]==||mp[i][j]==||mp[i][j]==);
tmp2+=(mp[i][j]==||mp[i][j]==||mp[i][j]==||mp[i][j]==);
tmp3+=(mp[i][j]==||mp[i][j]==||mp[i][j]==||mp[i][j]==);
}
else if(s/mi[j-]%==)
{
tmp1+=(mp[i][j]==||mp[i][j]==||mp[i][j]==||mp[i][j]==);
tmp2+=(mp[i][j]==||mp[i][j]==||mp[i][j]==||mp[i][j]==);
tmp3+=(mp[i][j]==-||mp[i][j]==||mp[i][j]==||mp[i][j]==);
}
now+=max(tmp1,max(tmp2,tmp3));
}
ans=max(ans,now);
}
printf("%d\n",ans);
return ;
}