文章目录

  • I.Pudding Store
  • H.Three Integers
  • C.Necklace
  • F.Cactus

补题链接:https://codeforces.com/gym/103415

I.Pudding Store

I. Pudding Store
time limit per test2.0 s
memory limit per test512 megabytes
inputstandard input
outputstandard output
159 is a boy. He has a pudding store.

There are n different puddings numbered from 1 to n lined up in a row in the pudding store. (Note that the i-th pudding in the row may not be the pudding with the number i.) Now, n students numbered from 1 to n are coming to sample these puddings in a specific way. That is, for the i-th student, he will sample each one of the first i puddings in the row. Sampling the pudding numbered i gives the sampler a satisfaction value of 2×i. And if the sum of all satisfaction values that the i-th student gets is divisible by i, we would say that the i-th student is satisfied.

Now, 159 wants to know, how many different arrangements of the puddings in a row that every student will be satisfied after sampling. Two arrangements are different, if there exists a pudding that its position is different. Note that the number of arrangements may be very large so he just needs the remainder after division by 998244353 of the result.

Input
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤10). Description of the test cases follows.

The first and only line of each test case contains one integer n (1≤n≤109) — the number of the puddings and the students.

Output
For each test case, print a single line that contains one integer — the number of satisfying arrangements modulo 998244353.

Example
inputCopy
3
1
2
3
outputCopy
1
2
6

题意:

  • 构造一个1-n的排列,需要满足前i项的和是2i的倍数,求能构造的这样的排列的方案数。
  • T组数据,每次给出一个n,求方案数%998244353。

思路:

  • 因为感觉条件比较苛刻,所以找一下规律,不难发现n>3时最后一项只能取1或n。
    对<=3的分类讨论,所以答案为6∗2n−36*2^{n-3}6∗2n−3, 快速幂即可。
  • 官方证明推导过程:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 998244353;
LL pows(LL a, LL x, LL p) { if(x==0)return 1; LL t = pows(a, x>>1, p); if(x%2==0)return t*t%p; return t*t%p*a%p; }int main(){int T;  cin>>T;while(T--){LL n;  cin>>n;if(n==1 || n==2)cout<<n<<"\n";else if(n==3)cout<<6<<"\n";else cout<<6ll*pows(2,n-3,mod)%mod<<"\n";}return 0;
}

H.Three Integers

H. Three Integers
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
You are given three non-negative integers a, b, and c. Find three positive integers x, y, and z that satisfy xmody=a, ymodz=b, and zmodx=c.

Input
The first line contains an integer t (1≤t≤105) — the number of test cases.

Each test case contains 3 integers a, b, c (0≤a,b,c≤109) on a single line.

Output
For each test case, if there are such three integers satisfying the condition, output “YES”, then output the three integers x, y, z (1≤x,y,z≤1018) on the following line, or “NO” otherwise.

Example
inputCopy
4
0 0 0
1 2 3
6 6 6
11 3 3
outputCopy
YES
1 1 1
YES
5 2 8
NO
YES
11 45 14

题意:

  • 给定三个非负整数 a、b 和 c, 求三个正整数 x、y 和 z。
    满足x mod y = a,y mod z = b 且 z mod x = c。
  • 0 ≤ a, b, c ≤ 1000,000,000, 输出满足 1 ≤ x, y, z ≤ 10^18。

思路:

  • 先找特殊的,当三个值相等时,当且仅当a=b=c=0时有解,否则无解。
  • 然后列一下通式,x = k1y+a, y = k2z+b, z = k3x+c。
    套到一起可以发现 x = k1k2k3x + k1k2c + k1b + a,y=k2k3x+k2c+b,因为k1,k2,k3>0。
    所以可以得到k1, k2, k3中至少有一个为0, 即有一个值和输入的值相等
  • 不妨设x=a,然后只需要适当构造,取适当的 u,v 使得 z = ua+c > b 且 y = vz+b > a成立即可(构造方案不唯一)。
  • vp时是队友写的,构造方案大致是相邻两个数作差再特判一下。补题时发现网上有大佬分类讨论推出了全部的公式,直接套公式就能过,借鉴了一下。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){int T;  cin>>T;while(T--){int a, b, c;  cin>>a>>b>>c;if(a==b && b==c){if(a!=0)cout<<"NO\n";else cout<<"YES\n1 1 1\n";continue;}LL x, y, z, k;  if(b > a){k = max(0, (c - a) / b) + 1;x = k * b + a;y = b;z = (k * b + a) * 2 + c;}else if(a > c){k = max(0, (b - c) / a) + 1;x = a;y = (k * a + c) * 2 + b;z = k * a + c;}else if(c > b){k = max(0, (a - b) / c) + 1;x = (k * c + b) * 2 + a;y = k * c + b;z = c;}cout<<"YES\n";cout<<x<<" "<<y<<" "<<z<<"\n";}return 0;
}

C.Necklace

C. Necklace
time limit per test1.0 s
memory limit per test512 megabytes
inputstandard input
outputstandard output
Bob has given Alice a necklace as her birthday gift. That necklace has N crystals, M of which catches her fancy. Formally, crystals with labels of 1…N are strung sequentially in a circle. And those catching her fancy are labelled n1,n2,…,nM.

Alice would like the necklace to be divided into M pieces. She asked Bob to sever the necklace into M pieces. Each piece should consist of a sequence of crystals as in the original necklace (i.e., the crystal labels are contiguous, except that 1 following N is accepted) and should include one crystal catching Alice’s fancy. Obviously, each crystal must belong to exactly one piece.

However, an excessively long piece of severed necklaces could not fit Alice’s slim neck. So she wants to know, among all possible severings as requested, what the minimum length of the longest piece from a severed necklace is. She wants you to answer this question.

Input
The first line of the input data contains 2 integers N and M (1≤M≤N<1018 and M≤106).

The second line contains M integers, the i-th of which represents ni. The ni’s are given in ascending order.

Output
You need to output your answer in one line.

Example
inputCopy
10 4
2 5 6 8
outputCopy
3
Note
As for the example: You can sever the necklace into [1,3],[4,5],[6,7],[8,10].

Considering huge scale of data, here is a way provided to help input faster:

#define gc()(is==it?it=(is=in)+fread(in,1,Q,stdin),(is==it?EOF:*is++):*is++)
const int Q=(1«24)+1;
char in[Q],*is=in,*it=in,c;
void read(long long &n){for(n=0;(c=gc())<'0'||c>'9';);for(;c<='9'&&c>='0';c=gc())n=n*10+c-48;
}

题意:

  • 长度为 n 的项链(是个环!)上有 m 个宝石,每个宝石要放在同一段里,求最长段长度的最小值。

思路:

  • 开始没看到是环,一眼二分答案想硬A上去,WA了两发才发现还有环这个操作。不过肯定还是二分答案+贪心的,就是贪心判断的方法需要改一下。

  • 每次check的时候从第一个位置开始贪心,一开始最大偏移量n-a[m]+a[1]-1,开个变量表示当前起始位置最大的偏移量,每跑一段区间都取个min,然后记录一下最开始的起始位置一共最大往前的偏移量即可。

  • 官方讲解:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    #define gc()(is==it?it=(is=in)+fread(in,1,Q,stdin),(is==it?EOF:*is++):*is++)
    const int Q=(1<<24)+1;
    char in[Q],*is=in,*it=in,c;
    void read(long long &n){for(n=0;(c=gc())<'0'||c>'9';);for(;c<='9'&&c>='0';c=gc())n=n*10+c-48;
    }const int maxn = 1e6+10;
    LL n, m, a[maxn];
    int check(LL x){LL mx = n-(a[m]-a[1]+1), mm = 0;   //最大能往左边移的量, 当前左移的量LL lst = 0, mx0 = mx;              //后一段要给前一段的大小for(int i = 1; i < m; i++){LL now = x-lst;           //当前能分的=x-给了上一段的if(now<=0)return 0;       //当前能分的是负数或0了,寄LL cc = a[i+1]-a[i];      //当前需要分的if(cc>now){               //足够分lst = cc-now;         //分一下mx = min(mx, now-1);  //更新最大偏移}else{lst = 0;                 //不够分LL m3 = min(mx, now-cc); //往左边移mm += m3;                //累加左移的量mx = min(mx-m3, cc-1);   //更新最大偏移}}LL ed = lst+mx0+1-x;if(x-lst>=mx0+1 || mm>=ed)return 1;return 0;
    }int main(){read(n);  read(m);for(int i = 1; i <= m; i++)read(a[i]);LL l = 1, r = n; while(l < r){LL mid = (l+r)>>1;if(check(mid))r = mid;else l = mid+1;}cout<<l<<"\n";return 0;
    }
    

F.Cactus

F. Cactus
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
An undirected connected graph is called a cactus, if and only if each edge of it belongs to at most one simple cycle. A simple cycle is a cycle that has no repeated vertices.

Now suppose there are fn cactuses of n distinct vertices, and the cactuses may have parallel edges and must not have self-loops, you need to calculate ∑ni=1∏j≠i1+fi−fifjfi−fj.

The sum of a zero-length sequence is 0, and the product of a zero-length sequence is 1.

Input
A single line contains an integer n (1≤n≤3×105).

Output
Suppose the reduced form of the answer is xy, and you only need to output the value of x×y998244351mod998244353.

Example
inputCopy
2
outputCopy
1
Note
In the first example, f1=1,f2=2, and the answer is 1.

题意:

  • 官方

思路:

  • 一开始是没看懂f表示的意思(没想到仙人掌),就代了一下各种值,结果发现n=2和n=3的时候不管带进去什么值,式子算出来的结果都是一样的
  • 然后开始打表,验证了一下真的是代什么都一样,把n=1~20的结果都跑出来,很明显是个斐波那契数列,所以就直接O(n)扫一遍就好啦。
  • 官方证明:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 3e5+10;
const LL mod = 998244353;
LL f[maxn];
int main(){LL n;  cin>>n;f[1] = f[2] = 1;for(int i = 3; i <= n; i++){f[i] = (f[i-1]+f[i-2])%mod;}cout<<f[n]<<"\n";return 0;
}

2021第7届中国大学生程序设计竞赛CCPC广州站, 签到题4题相关推荐

  1. 2021第7届中国大学生程序设计竞赛CCPC桂林站, 签到题5题

    文章目录 A.Hero Named Magnus I. PTSD G. Occupy the Cities E. Buy and Delete D.Assumption is All You Need ...

  2. 2022第8届中国大学生程序设计竞赛CCPC威海站, 签到题7题

    文章目录 E.Python Will be Faster than C++ A.Dunai G.Grade 2 J.Eat, Sleep, Repeat C.Grass D.Sternhalma I. ...

  3. 2019中国大学生程序设计竞赛(CCPC)-网络选拔赛-第七题Shuffle Card

    文章目录 1.大赛题目 2.中文翻译 3.代码案例 4.解题思路 4.1代码举例 1.大赛题目 Shuffle Card Time Limit: 2000/1000 MS (Java/Others) ...

  4. 挑战程序设计竞赛_我系首次参加第六届中国大学生程序设计竞赛网络预选赛

    点击上方蓝字关注  「龙外信息工程系」 讲述有温度的故事    传递有态度的思想 2020年9月20日12时至17时,第六届中国大学生程序设计竞赛网络赛预选赛在杭州电子科技大学OJ成功举办,黑龙江外国 ...

  5. 秦皇岛计算机编程大赛,南科大学子在第六届中国大学生程序设计竞赛(秦皇岛)获多个奖项...

    2020年10月18日,第六届中国大学生程序设计竞赛(China Collegiate Programming Contest,简称CCPC)(秦皇岛)暨2020中国大学生程序设计竞赛女生专场在秦皇岛 ...

  6. 2021中国大学生程序设计竞赛(CCPC),烤仔与你不见不散!

    今天也是见到超多学霸的一天呢! 因为,CCPC 的参赛选手们来看烤仔啦!北京航空航天大学.北京交通大学等高校共 95 名总决赛参赛选手在 5 月 28 日来到 Conflux 参观.交流. 由中国大学 ...

  7. 2020年中国大学生程序设计竞赛(CCPC) - 网络选拔赛部分题解

    前言 既培养算法知识,又能学习按摩手法,我们还有专业的算命大师帮你窥察天机. 这还犹豫什么,快来加入我们.前10名还能请大师免费帮你看风水,让你死后也能安心. 我怕不是进了一个人才市场- Expres ...

  8. 浙江大学计算机学院 英语竞赛 陈星,喜报 | 浙大代表队获得CCPC中国大学生程序设计竞赛冠军...

    浙江大学Wheatfield with Crows队在2019年10月20日下午2时结束的CCPC中国大学生程序设计竞赛厦门赛站中获得冠军,来自复旦大学和清华大学的队伍分获亚军和季军. 本次比赛于20 ...

  9. 第45届国际大学生程序设计竞赛(ICPC)银川站太原理工大学收获4枚奖牌

    第45届国际大学生程序设计竞赛(ICPC)银川站,由宁夏理工学院承办,于2021年5月15-16日在宁夏的石嘴山市进行. 太原理工大学在比赛中获得2银2铜共4枚奖牌的好成绩. 参加本次比赛的四个队,涵 ...

最新文章

  1. pytorch python区别_pytorch源码解析:Python层 pytorchmodule源码
  2. 阿里云云原生应用平台总经理丁宇:“连接、合作、赋能”,携手加速器伙伴助力企业云上创新
  3. linux脚本 的使用,linux shell脚步使用讲解
  4. sqlserver没有维护计划_设定数据库备份计划,安全放心不怕事!
  5. http端口_PhpStorm 修改默认端口号63342
  6. ThinkPhp知识大全(非常详细)
  7. mysql8和5.7区别_mysql8.0与mysql5.7安全加密小差别
  8. linux安装网卡驱动tgz,Linux安装网卡驱动
  9. 神经网络入门学习-一些基本的概念+不含隐层
  10. PMBOK--项目整合管理
  11. java web参考文献_javaweb外文参考文献
  12. sqlserver连接问题圣经
  13. Meterpreter 脚本列表
  14. 西门子MM440变频器调试小记
  15. 5种最流行的密码破解工具:保护您的账号
  16. UVA 10105 Polynomial Coefficients
  17. python.exe无法找到入口 无法定位程序输入点
  18. 新品再续传奇 九联科技AX1800 WIFI6路由器上市受追捧
  19. 双馈风机并网simulink模型
  20. golang中os/signal包的使用

热门文章

  1. [乱七八糟][转]这不是你想象中的软件产业
  2. Javascript(JS) leetcode 200. 岛屿数量
  3. 五、Hystrix断路器
  4. 视频显示设备和光栅扫描系统
  5. 红警ol总是服务器满 可服务区显示流程,红警OL:11月27日部分服务器数据互通合服公告...
  6. 计算机网络电视如何配置,电脑投屏到电视无线怎么设置(手把手教你设置技巧)...
  7. 用python做飞机大战打到不同部位扣分不同_python制作飞机大战需要哪些python术语...
  8. 15个SEO学习的国外SEO博客
  9. 《杜拉拉升职记》职场36计
  10. 【Python案例】基于Pygame黑白棋游戏(附源码)