长时间没码代码后,对题目明显变得生疏,还是需要找几道水题来练练手
1129: An Old Problem
思路:典型的矩阵交换行列的题,建立索引,利用交换索引替代直接对矩阵进行交换
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+10;
int a[maxn][maxn];
int x[maxn],y[maxn];
int main()
{
int m,n,k;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
for(int i=0;i<n;i++)
{
y[i] = i;
for(int j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
}
}
for(int j=0;j<m;j++) x[j] = j;
while(k--)
{
int p,a,b;
scanf("%d%d%d",&p,&a,&b);
if(p==0)
swap(y[a-1],y[b-1]);
else
swap(x[a-1],x[b-1]);
}
for(int i=0;i<n;i++)
{
printf("%d",a[y[i]][x[0]]);
for(int j=1;j<m;j++)
{
printf(" %d",a[y[i]][x[j]]);
}
printf("\n");
//printf("%d\n",a[y[i]][x[m-1]]);
}
}
return 0;
}
1133: Special Judge
思路:就是个简单的模拟题,模拟整个判定过程即可
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+10;
typedef long long ll;
ll a[maxn],b[maxn];
int main()
{
int k,al,bl;
while(scanf("%d%d%d",&al,&bl,&k)!=EOF)
{
for(int i=0;i<al;i++) scanf("%lld",&a[i]);
for(int i=0;i<bl;i++) scanf("%lld",&b[i]);
int sit = -1;
for(int i=2;i<bl;i++)
if(b[i]-b[i-1]!=b[i-2])
sit=0;
if(sit==0) printf("Wrong Answer - The participant's answer does not obey the recursion\n");
else
{
int pos = 0;
for(int i=0;i<al;i++)
{
if(a[i]==b[pos])
pos++;
if(pos==bl)
break;
}
if(pos<bl) printf("Wrong Answer - The participant's answer is not a subsequence of input\n");
else if(bl>k) printf("System Error - The participant gets better answer than jury's\n");
else if(bl==k) printf("Accepted - Ok, ok\n");
else printf("Wrong Answer - The jury gets better answer than participant's\n");
}
}
return 0;
}
1292: World Game
思路:简单匹配题,从母串中匹配子序列,只需要统计字母次数即可,最终输出最长子序列
#include <bits/stdc++.h>
using namespace std;
const int maxn = 30;
char dic[maxn];
char alphabet[maxn];
int num[maxn];
int main()
{
while(scanf("%s",dic)!=EOF)
{
int diclen = strlen(dic);
int n;
scanf("%d",&n);
int re = 0;
while(n--)
{
memset(num,0,sizeof num);
for(int i=0;i<diclen;i++) num[dic[i]-'a']++;
scanf("%s",alphabet);
int alplen = strlen(alphabet);
int len = 0;
for(int i=0;i<alplen;i++)
{
num[alphabet[i]-'a']--;
if(num[alphabet[i]-'a']<0) len = -1;
}
if(len==0&&alplen>re) re = alplen;
}
printf("%d\n",re);
}
return 0;
}
1293: Arch0n's interesting game
思路:对牌取最小,找出第k大方案,一看就是个无法暴力的找规律题,那么就开始推公式咯
n*(n+1)/2=k
n^2+n=2*k
(n+1/2)^2=2*k+1/4
n=sqrt(2*k+1/4)-1/2
于是直接套公式即可,注意从大到小排列,向上取整,由于取最小最后得到的值+1即可
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4+10;
const double eps = 1e-7;
int a[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++) scanf("%d",&a[i]);
sort(a,a+n, greater<int>() );
int re = (int)(sqrt(2.0*(double)(k)+1.0/4.0-eps) - 1.0/2.0)+1;
printf("%d\n",a[re]);
}
return 0;
}