SDUT 2020 Summer Individual Contest - 7(for 19) Div.1题解

I - Odd Gnome

这是一个签到题,很简单,按照题目要求模拟一下就行,有时可以结合样例想一下

#include <bits/stdc++.h>
#define fi first
#define se second
#define eps 1e-8
#define ll long long
#define ull unsigned long long
#define pb push_back
#define maxn 5000010
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define P pair<ll, ll>
#define pi acos(-1)
#define lson l,mid,rt*2
#define rson mid+1,r,rt*2+1
#define lowbit(x) (x&(-x))
#define SZ(x) ((int)(x).size())
#define met(a,x) memset(a,x,sizeof(a))
#define openin(x) freopen(x, "r", stdin)
#define openout(x) freopen(x, "w",stdout)
#define rep(i,a,b) for(ll i = a;i <= b;i++)
#define bep(i,a,b) for(ll i = a;i >= b;i--)
using namespace std;
ll mod = 998244353;
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

ll qpow(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
int main()
{
    int n,i,m,a[10010];
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        for(i=1; i<=m; i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=2; i<m; i++)
        {
            if(a[i]>a[i-1]&&a[i]>a[i+1]&&a[i-1]<a[i+1])
            {
                printf("%d\n",i);
            }
            if(a[i]<a[i-1]&&a[i]<a[i+1]&&a[i-1]<a[i+1])
            {
                printf("%d\n",i);
            }
        }
    }
    return 0;
}

F - GlitchBot

每一步输入三个指令,安指令行走,从0,0走到x,y,中间有一步是错误的,找到那一步,并把它改正输出,这个题的数据比较小,直接暴力修改每一步就行

#include <bits/stdc++.h>
#define fi first
#define se second
#define eps 1e-8
#define ll long long
#define ull unsigned long long
#define pb push_back
#define maxn 5000010
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define P pair<ll, ll>
#define pi acos(-1)
#define lson l,mid,rt*2
#define rson mid+1,r,rt*2+1
#define lowbit(x) (x&(-x))
#define SZ(x) ((int)(x).size())
#define met(a,x) memset(a,x,sizeof(a))
#define openin(x) freopen(x, "r", stdin)
#define openout(x) freopen(x, "w",stdout)
#define rep(i,a,b) for(ll i = a;i <= b;i++)
#define bep(i,a,b) for(ll i = a;i >= b;i--)
using namespace std;
ll mod = 998244353;
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

ll qpow(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
char s[100];
int a[10000];
int n,x,y;

int bianli()
{
    int l=0;
    int x1=0;
    int y1=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        {
            x1=x1+dx[l];
            y1=y1+dy[l];
        }
        else if(a[i]==1)
        {
            l=(l+3)%4;
        }
        else if(a[i]==2)
        {
            l=(l+1)%4;
        }
    }
    return x1==x&&y1==y;
}


int main()
{
    int i;
    int f=0;
    scanf("%d%d%d",&x,&y,&n);
    for(i=0; i<n; i++)
    {
        scanf("%s",s);
        if(strcmp(s,"Forward")==0)
        {
            a[i]=0;
        }
        else if(strcmp(s,"Left")==0)
        {
            a[i]=1;
        }
        else if(strcmp(s,"Right")==0)
        {
            a[i]=2;
        }
    }
    for(i=0; i<n; i++)
    {
        int t=3;
        if(f==1)
            break;
        while(t--)
        {
            a[i]=(a[i]+1)%3;
            if(bianli())
            {
                printf("%d ",i+1);
                if(a[i]==0)
                {
                    printf("Forward\n");
                }
                else if(a[i]==1)
                {
                    printf("Left\n");
                }
                else if(a[i]==2)
                {
                    printf("Right\n");
                }
                f=1;
                break;
            }
        }
    }
    return 0;
}

B - Bumped!

题意:有n种面额的货币,如果能保证所以金额,用贪心思想算出的货币张数(每次减先大面额的货币)和 正确的货币张数是相同的,就是规范的(输出canonical),如果贪心算出的货币张数比正确算出的多,那就是不规范的(输出non-canonical)

转移方程 dp[i] = d[i - b[j] ] + 1;(dp[i]代表剩余金额为i时已经拥有的张数,b[j]代表第j张钱的面额)

#include <bits/stdc++.h>
#define fi first
#define se second
#define eps 1e-8
#define ll long long
#define ull unsigned long long
#define pb push_back
#define maxn 5000010
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define P pair<ll, ll>
#define pi acos(-1)
#define lson l,mid,rt*2
#define rson mid+1,r,rt*2+1
#define lowbit(x) (x&(-x))
#define SZ(x) ((int)(x).size())
#define met(a,x) memset(a,x,sizeof(a))
#define openin(x) freopen(x, "r", stdin)
#define openout(x) freopen(x, "w",stdout)
#define rep(i,a,b) for(ll i = a;i <= b;i++)
#define bep(i,a,b) for(ll i = a;i >= b;i--)
using namespace std;
ll mod = 998244353;
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

ll qpow(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

int a[2000000],b[2000000];
int dp[2000000];
int main()
{
    int n,i,j;
    memset(dp,inf,sizeof(dp));
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    dp[0]=0;
    for(i=1; i<=n; i++)
    {
        for(j=0; j<=2000000; j++)
        {
            if(j>=a[i])
            {
                dp[j]=min(dp[j],dp[j-a[i]]+1);
            }
        }
    }
    for(i=0; i<=2000000; i++)
    {
        for(j=1; j<=n; j++)
        {
            if(i>=a[j])
            {
                b[i]=b[i-a[j]]+1;
            }
        }
    }
    int f=0;
    for(i=0; i<2000000; i++)
    {
        if(b[i]!=dp[i])
        {
            f=1;
            break;
        }
    }
    if(f==1)
    {
        printf("non-canonical\n");
    }
    else
    {
        printf("canonical\n");
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值