Number Game
Number Game
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 30 Accepted Submission(s) : 10
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
Output
Sample Input
1 12 3 A 1 7 B 3 5 Q 3
Sample Output
4 6 11
Author
Source
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define N 10001
using namespace std;
int hash[N];
int rc[N];
int main()
{
int T;
int n,m;
int i,j;
char op;
int l,r;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
hash[i]=i,rc[i]=i;
while(m--)
{
getchar();
scanf("%c",&op);
if(op=='A') //写好后发现A和B的操作完全一样,可以放一起
{
scanf("%d%d",&i,&j);
swap(rc[hash[i]],rc[hash[j]]);
swap(hash[i],hash[j]);
}
else if(op=='B')
{
scanf("%d%d",&i,&j);
swap(rc[hash[i]],rc[hash[j]]);
swap(hash[i],hash[j]);
}
else
{
scanf("%d",&i);
j=hash[i];
if(j>n/2)
{
l=j-1;if(l==n/2) l=n;
r=j+1;if(r>n) r=n/2+1;
j=j-n/2;
printf("%d %d %d\n",rc[l],rc[r],rc[j]);
}
else
{
l=j-1;if(l==0) l=n/2;
r=j+1;if(r>n/2) r=1;
j=j+n/2;
printf("%d %d %d\n",rc[l],rc[r],rc[j]);
}
}
}
}
}
//小修改下
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define N 10001
using namespace std;
int hash[N];
int rc[N];
int main()
{
int T;
int n,m;
int i,j,l,r;
char op;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
hash[i]=i,rc[i]=i;
while(m--)
{
getchar();
scanf("%c",&op);
if(op=='A'||op=='B')
{
scanf("%d%d",&i,&j);
swap(rc[hash[i]],rc[hash[j]]);
swap(hash[i],hash[j]);
}
else
{
scanf("%d",&i);
j=hash[i];
if(j>n/2)
{
l=j-1;if(l==n/2) l=n;
r=j+1;if(r>n) r=n/2+1;
j=j-n/2;
printf("%d %d %d\n",rc[l],rc[r],rc[j]);
}
else
{
l=j-1;if(l==0) l=n/2;
r=j+1;if(r>n/2) r=1;
j=j+n/2;
printf("%d %d %d\n",rc[l],rc[r],rc[j]);
}
}
}
}
}