Problem C: 兰顿蚂蚁
模拟一下就好了,把每个实现的功能分开写成独立的函数,不然写在一块儿会很乱。注意转换方向的时候不要弄错了(我就弄错了一次)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <map>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#define go(i,a,b) for(int i=a;i<b;i++)
#define og(i,a,b) for(int i=a;i>b;i--)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn = 1e2 + 5;
typedef long long ll;
int a[maxn][maxn];
int flag = 0;
int color_now(int x,int y)
{
if(a[x][y] == 1)
return 1;
return 0;
}
char change_s(char c,int flag)
{
char afterchange_s = c;
if(!flag)//左转
{
if(c == 'U')
afterchange_s = 'L';
if(c == 'D')
afterchange_s = 'R';
if(c == 'L')
afterchange_s = 'D';
if(c == 'R')
afterchange_s = 'U';
}
else
{
if(c == 'U')
afterchange_s = 'R';
if(c == 'D')
afterchange_s = 'L';
if(c == 'L')
afterchange_s = 'U';
if(c == 'R')
afterchange_s = 'D';
}
return afterchange_s;
}
void change_a(int x,int y)
{
if(!a[x][y])
a[x][y] = 1;
else
a[x][y] = 0;
}
int next_x(int x,char s)
{
if(s == 'D')
return x + 1;
else if(s == 'U')
return x - 1;
else
return x;
}
int next_y(int y,char s)
{
if(s == 'L')
return y - 1;
else if(s == 'R')
return y + 1;
else
return y;
}
int main()
{
int m,n,x,y,k;
char s;
cin>>m>>n;
go(i,0,m)
{
go(j,0,n)
{
cin>>a[i][j];
}
}
cin>>x>>y>>s>>k;
go(i,0,k)
{
s = change_s(s, color_now(x, y));
change_a(x, y);
x = next_x(x, s);
y = next_y(y, s);
}
printf("%d %d\n",x,y);
return 0;
}
Problem L: 数字游戏
只要look at栋栋报的数就好了
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <map>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#define go(i,a,b) for(int i=a;i<b;i++)
#define og(i,a,b) for(int i=a;i>b;i--)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn = 1e2 + 5;
typedef long long ll;
int main()
{
ll n,k,t,x = 1,ans = 1,left = 1,r;
scanf("%lld%lld%lld",&n,&k,&t);
r = n;
for(int i = 1;i < t;i++)
{
x += (left + r) * n / 2;
x %= k;
ans += x;
left = 1 + i * n;
r = n + i * n;
}
printf("%lld\n",ans);
return 0;
}