A
题意:输入n行12列的字符串,对于每行字符串而言,从i=1-12开始遍历,每个字符串可以分成i行12/i列。若有一列的值全部为x,则输出i*12/i.
模拟皆可
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=50;
char s[maxm];
int x[maxm],y[maxm];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
memset(x,0,sizeof(x));
memset(y,0,sizeof(y));
scanf("%s",s);
int cnt=0;
for(int i=1; i<=12; i++)
{
if(12%i==0)
{
for(int j=0; j<12/i; j++)
{
int ok=1;
for(int k=j; k<12; k+=12/i)
{
if(s[k]=='O')
{
ok=0;
break;
}
else
{
continue;
}
}
if(ok)
{
x[cnt]=i;
y[cnt++]=12/i;
break;
}
}
}
}
printf("%d ",cnt);
for(int i=0; i<cnt; i++)
{
printf("%dx%d ",x[i],y[i]);
}
printf("\n");
}
return 0;
}
B:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e3+10;
char s[maxm][maxm];
int vis[maxm];
int main()
{
int m,n;
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(vis,0,sizeof(vis));
int ok=0;
int cnt=0;
for(int i=0;i<m;i++)
{
scanf("%s",s[i]);
int x=0,y=0;
for(int j=0;j<strlen(s[i]);j++)
{
if(s[i][j]=='G')
{
x=j;
}
if(s[i][j]=='S')
{
y=j;
}
}
if(x>y)
{
ok=1;
}
else if(!vis[y-x])
{
cnt++;
vis[y-x]=1;
}
}
if(ok)
{
printf("-1\n");
continue;
}
printf("%d\n",cnt);
}
return 0;
}
C
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk).
The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.
Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!
The first line of the input contains fix integers n, m, x, y, z, p (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105).
Each of the following p lines contains two integers xk, yk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.
For each of the p candies, print on a single line its space-separated new coordinates.
3 3 3 1 1 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3
1 3 1 2 1 1 2 3 2 2 2 1 3 3 3 2 3 1
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
QWER REWQ ASDF -> FDSA ZXCV VCXZ
解:想,对于转x次,没4次回到原点,则x%=4.同理y&=1.z%=4;接下来模拟就可以了
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxm=1e5+10;
int a[maxm];
int b[maxm];
int main()
{
int n,m,x,y,z,p;
while(scanf("%d%d%d%d%d%d",&m,&n,&x,&y,&z,&p)!=EOF)
{
x%=4;
y&=1;
z%=4;
for(int i=0;i<p;i++)
{
int temp1=m,temp2=n;
scanf("%d%d",&a[i],&b[i]);
for(int j=0;j<x;j++)
{
swap(a[i],b[i]);
b[i]=temp1+1-b[i];
swap(temp1,temp2);
}
if(y)
{
b[i]=temp2+1-b[i];
}
for(int j=0;j<z;j++)
{
swap(a[i],b[i]);
a[i]=temp2+1-a[i];
swap(temp1,temp2);
}
}
for(int i=0;i<p;i++)
{
printf("%d %d\n",a[i],b[i]);
}
}
return 0;
}