竞赛准备赛-4-C:兰顿蚂蚁 L: 数字游戏

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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值