I. Command Sequence CCPC2021网络赛

Problem I. Command Sequence
Input fifile:
standard input
Output fifile:
standard output
Time limit: 1 second
Memory limit: 256 megabytes
There is a robot that can move by receiving a sequence of commands.
There are four types of command in the command sequence:
U : robot moves one unit up.
不同年份的CCPC网络有不同的题目及解答: - 2018年CCPC网络:给一张竞图,对于所有的4元组,若为四元环贡献是1,有两个点的出度是2则贡献是 -1。先假设所有四元组都是四元环,这部分对答案的贡献是A(n,4)。对于非四元环的四元组,必然存在一个点出度是2,枚举每个度数>=2的点,其对答案的贡献是A(deg[i],2)*(n - 3)*4 ,所以最终答案ans = A(n,4) - ΣA(deg[i],2)*(n - 3)*4 ,这其实要求ΣC(deg[i],2),C(deg,2)=deg*(deg - 1)/2 ,当前度数为n,度数每增加1,对于这个点贡献增加n,可暴力连边跑费用流求解[^2]。 - 2021CCPC网络:发现规律,先将剩余的1或2或3构造出来,剩下的四个一组构造。代码实现如下: ```cpp #include<bits/stdc++.h> using namespace std; int main(void) { int t; cin>>t; while(t--) { int n; cin>>n; string ans; if(n%4==1) n=n-1,ans+="1"; else if(n%4==2) n=n-2,ans+="0001"; else if(n%4==3) n=n-3,ans+="01"; for(int i=1;i<=n/4;i++) ans+="1001"; cout<<ans.size()<<endl; cout<<ans<<endl; } return 0; } ``` 该题1009为Command Sequence,难度一般,知识点涉及前缀和与哈希[^4]。 - 2016年CCPC网络:一个星球一年有73天,另一个一年有137天,给定第n天,判断这一天是否同时是两个星球一年中的第一天,即判断n是否同时整除73和137,因n超大,使用紫书的大数模去一个较小的数的方法,代码如下: ```cpp #include <cstdio> #include <string> #include <cstring> #include <iostream> using namespace std; char n[10000010]; int m; int main(){ int m = 10001; int cas = 1; while(~scanf("%s",n)){ int len = strlen(n); int ans = 0; for(int i=0;i < len;i++){ ans = (int)(((long long)ans*10+n[i]-'0')%m); } printf("Case #%d: ",cas++); if (ans == 0) printf("YES\n"); else printf("NO\n"); } return 0; } ``` [^3]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值