2020(ICPC)江西省程序设计竞赛正式赛

B 签到题

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        if(m*(m+1)/2<=n)puts("possible");
        else puts("impossible");
    }
    return 0;
}

E Colour Sequence
题意:给出一个字符串,每个字符代表一种颜色,输出满足所有颜色出现次数均为偶数次的连续子串的个数
思路:位运算
分析:0<=Ci<=20,用二进制数来表示不同颜色获取每种颜色出现的次数是奇数次还是偶数次,因为二进制只有0和1两种表示,我们可以假设1为奇数状态,0为偶数状态,如果当前位置状态是奇数状态,那么为了构成偶数状态,必然需要前面的也是奇状态并与之构成偶状态才能符合条件,因此从前面那个相同状态到当前状态的区间就会是一个全偶的状态,因此只要想办法解决怎么实现状态转换和区间计数就可以解决这个问题了。首先我们可以开一个数组来存储每种颜色二进制表示:
a[0]------01
a[1]------10
a[2]------100

a[i]-------(1<<i)
对需要输入的每一个数进行异或处理并求和。
初始状态设一个变量为tot=0,二进制表示是000000…00:
1.对第一个读入的数字为1,tot和1对应的a[1]=10异或得到结果10
2.第二次读入0,tot^a[0] (01)—>11
3.第三次读入0,tot^a[0]—>10
4.第四次读入1,tot^a[1]—>00
5.第五次读入0,tot^a[0]—>01
6.第六次读入0,tot^a[0]—>00
7.第七次读入0,tot^a[0]—>01
对第一次读入后的状态10,前面没有与之相同的状态,res+=0,cnt[10]++;
对于状态2,前面没有相应的同状态11与之对应,res+=0,cnt[11]++;
对于状态3,前面有同状态10,因此res+=cnt[10],cnt[10]++;

a状态减去b状态相当于选取[b+1,a]的子区间,这样每次都是寻找1~x之间的状态相减,但是这样不会把1给选进去,但是1其实是符合条件的,因为默认什么都不选的时候是偶数状态,所以开始让cnt[0]=1
(ps:赛后请教z神知道的)
ac

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;
const int N=(1<<22);
ll a[25],cnt[N];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<=20;i++)a[i]=(1<<i);
    cnt[0]=1;
    ll res=0,tot=0;
    int x;
    for(int i=0;i<n;i++){
        cin>>x;
        tot^=a[x];
        res+=cnt[tot];
        cnt[tot]++;
    }
    cout<<res<<endl;
    return 0;
}

I Simple Math Problem数学公式推导题
注意:题目出现了A,B,C,D,E,F,暗示是16进制,所以要按照16进制去推上三角和下三角的规律,A~F实际上对应的是11 ~ 15,而18实际上对应的是24.
分析:推导过程比较简单,略

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;

int main()
{
    ll n,x,y;
    scanf("%lld%lld%lld",&n,&x,&y);
    ll ans=0;
    if(x+y<=n-1)ans=y*(y+1)/2+x*(2*y+x+3)/2;
    else{
        ll res=y*(y+1)/2+(n-y-1)*(n+y+2)/2;
        ans=res+(x+y+1-n)*n-(x+y+1-n)*(x+y-n)/2;
        //cout<<(x+y+1-n)*n-(x+y+1-n)*(x+y-n)/2<<endl;
    }
    printf("%lld\n",ans);
    return 0;
}

M 签到题

#include<iostream>
#include<string>

using namespace std;

int main()
{
    string sa,sb;
    cin>>sa>>sb;
    cout<<sa+sb<<endl;
    return 0;
}

G 数学

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;
const ll mod=998244353;

ll quick_pow(ll x,ll y)
{
    ll ans=1;
    while(y){
        if(y&1)ans=(ans*x)%mod;
        x=(x*x)%mod;
        y>>=1;
    }
    return ans%mod;
}

int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll res=quick_pow(m+1,n)%mod;
    printf("%lld\n",res);
    return 0;
}
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值