2020.9.25--2020中国大学生设计大赛总结
1010.Reports
Problem Description
Because of Covid-19, Kanade needs to report every time when entering and leaving school. Now you want to check if Kanade's reports on a certain day are correct.
A sequence of reports is correct if and only if there does not exist two consecutive and same reports.
A sequence of reports is correct if and only if there does not exist two consecutive and same reports.
Input
There are T
test cases in this problem.
The first line has one integer T
.
For every test case:
The first line has one integer n
which denotes the number of times Kanade reported on a certain day.
The second line has n
integers a
1
,a
2
,a
3
,⋯,a
n![]()
, a
i![]()
denotes the type of the i
-th report. a
i
=0
denotes a leaving school report and a
i
=1
denotes an entering school report.
1≤T≤100
3≤n≤50
0≤a
i
≤1![]()
The first line has one integer T
For every test case:
The first line has one integer n
The second line has n
1≤T≤100
3≤n≤50
0≤a
Output
For every test case, output ``YES'' if Kanade's reports are correct, otherwise output ``NO'' (without quotes)
Sample Input
4
3
1 1 1
3
1 0 1
5
0 1 0 1 0
4
1 0 1 1
Sample Output
NO
YES
YES
NO
题意:K每次进出学校都要进行上报,进校用“1”表示,出校为“0”,只有当两个连续的报告序列不同时报告才正确,否则错误。
解法:直接判断两个连续的数是否不同
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,i,s[100]; cin>>n; for(i=0;i<n;i++) { cin>>s[i]; } int k=0; for(i=0;i<n-1;i++) { if(s[i]==s[i+1]) { k=1; cout<<"NO"<<endl; break; } } if(k==0)cout<<"YES"<<endl; } }
1003.Express Mail Taking
Problem Description
Besides on the traditional classes,Baby Volcano also needs to learn how to take the express mails.
Usually express mails are stored in cabinets. In Baby Volcano's school,there are n
cabinets in a row,numbered by 1
to n
. The distance between two adjacent cabinets is 1
, and the entrance is at the cabinet 1
. Among all n
cabinets,the one numbered k
is special and it is used to enter the code and open the cabinet door.
Baby Volcano has m
express mails to take,the i
-th is in the cabinet a
i![]()
.
Two express mails will not be stored in the same cabinet. Also there is no express mail in the cabinet k
.
To prevent expresses from being stolen, Baby Volcano have to take these express mails one by one, starting at the entrance. Generally, if he wants to take the express mail i
, he have to walk to cabinet k
first to enter the code, and then walks to cabinet a
i![]()
. After taking the last one,he walks to the entrance.
There are so many express mails to take, so Baby Volcano wants to find a taking order which minimize the distance he walks.
Usually express mails are stored in cabinets. In Baby Volcano's school,there are n
Baby Volcano has m
Two express mails will not be stored in the same cabinet. Also there is no express mail in the cabinet k
To prevent expresses from being stolen, Baby Volcano have to take these express mails one by one, starting at the entrance. Generally, if he wants to take the express mail i
There are so many express mails to take, so Baby Volcano wants to find a taking order which minimize the distance he walks.
Input
The first line contains one integer T(1≤T≤100)
,the number of testcases.
For each test cases,the first line contains three integer n,m,k(1≤k≤n≤10
9
,1≤m<min(n,10
6
))
The next line contains m
integer,the i
-th stand for a
i
(1≤a
i
≤n,a
i
≠k)
.
The input guarantees that ∑m≤2×10
6![]()
**Note:Because of the large input,it is prefered to use scanf instead of cin.**
For each test cases,the first line contains three integer n,m,k(1≤k≤n≤10
The next line contains m
The input guarantees that ∑m≤2×10
**Note:Because of the large input,it is prefered to use scanf instead of cin.**
Output
For each test case,Output a single line contains one integer,representing for the minimal walking distance.
Sample Input
2
10 2 5
6 7
10 2 5
3 4
Sample Output
14
10
题意:除了传统的课程,小火山还需要学习如何接快递。
快件通常存放在橱柜里。在小火山的学校里,有n个橱柜排在一排,编号1到n。相邻两个柜子之间的距离为1,入口在柜子1处。在n个机柜中,编号为k的机柜是特殊的,用来输入代码,从而打开机柜门。小火山有m快递要取,第i个在柜子ai里。
两封快件不会存放在同一个柜子里。而且也没有特快专递。
解法:输入一次代码只能打开一个机柜,先取编号大的快件再取编号小的快件,可以发现;除了最后一个快递,其余快递都要从k出发到ai再返回k,所以要考虑最后一个快递的距离
如:10 2 5
3 4
路线:1-5 要走4
5-4 1
4-5 1
5-1 4
总长为10
若要先取3号快件为:
1-5 4
5-3 2
3-5 2
5-1 4
总长为12
#include<bits/stdc++.h> #include<cstdio> using namespace std; int main() { int t; cin>>t; while(t--) { long long n,m,k,i,j; scanf("%lld%lld%lld",&n,&m,&k); long long s[m+5]; for(i=0;i<m;i++) { scanf("%lld",&s[i]); } sort(s,s+m);//从小到大排列 long long sum=0; for(i=m-1;i>=0;i--) { if(s[i]>k) { sum+=(s[i]-k)*2; } else { sum+=(k-s[i])*2;//此处多加了k与最小编号的快件的距离 } } if(s[0]<k) { sum+=(k-1)*2;//加上一开始从1到k的距离以及从k返回到1的距离 sum-=(k-s[0])*2;//当最小编号小于k时要减去k->ai及ai->k多加的距离 } else { sum+=(k-1)*2;//最小编号大于k时直接加上1->k及k->1的距离 } printf("%lld\n",sum); } }
1007.CCPC Training Class
Problem Description
Baby volcano is helping his CCPC coach preparing a new CCPC training contest. He wants to generate high quality data on border tree(There is no need to know what border tree is), but he encounters some troubles. Could you please help him?
In this paragraph we formally define the data quality problem. For some string s=s
1
s
2
s
3
⋯s
n![]()
, we use s[l:r]
to denote the substring starts from l
and ends at r
, if l>r
, s[l:r]
is empty. We further define:
, then we define D(i)
to denote the length of border chain at position i
:
of this string is define as the maximum of D
:
is as large as possible.
Now given a string s
, you could permute s
arbitrarily. What is the maximum quality W
you could reach after permuting s
?
In this paragraph we formally define the data quality problem. For some string s=s
Lborder
i
=max{0≤j<i | s[1:j]=s[i−j+1:i]}![]()
to denote the longest border at some position iD(i)={0
D(LBorder
i
)+1![]()
i=0
i>0![]()
![]()
![]()
The quality WW=max
i=0
n
D(i)![]()
To distinguish border tree with naive brute force algorithms, baby volcano need to generate strings such that its quality WNow given a string s
Input
In the first line there is a number T
(T≤20
), denotes the number of test cases.
In the next T
lines, for each line there is a string s
(1≤|s|≤10
5![]()
), denotes the input string, all inputs are formed in lowercases.
In the next T
Output
Output T
lines, for each line, you need to output ''Case #t: m''(without quotes), where t is the index of this test case, m is the maximum quality you could reach after permuting.
Sample Input
5
abcde
sankaranarayanan
abbccaabc
programming
monotone
Sample Output
Case #1: 1
Case #2: 7
Case #3: 3
Case #4: 2
Case #5: 3
题意:找出字符串s中出现次数最多的那个字母的次数;
#include<bits/stdc++.h> using namespace std; int main() { int t,j=1; cin>>t; while(t--) { string s; int i,m,b[1000]={0}; cin>>s; m=s.size(); int max=-1; for(i=0;i<m;i++) { b[s[i]-'a']++; if(b[s[i]-'a']>max)max=b[s[i]-'a']; } cout<<"Case #"<<j<<": "<<max<<endl; ++j; } }
(以下均来自比赛上大佬的代码)
1001.Art Class
Problem Description
This class is on art. Mr. Picasso gives every baby a piece of white drawing paper and let them paint on it.
Baby Volcano is going to color the drawing paper black. For convenience, the drawing paper can be regarded as a Cartesian coordinate system, and initially, all points on it is white.
Baby Volcano plans to paint the drawing paper in n
steps. In the i
th step, he will color rectangular R
i![]()
black, where the lower left corner of R
i![]()
is (l
i
,0)
, the upper right corner of R
i![]()
is (r
i
,h
i
)
.
Let P
i![]()
be the drawing paper after the first i
steps, your task is to calculate the perimeter of black area on P
i![]()
.
Baby Volcano is going to color the drawing paper black. For convenience, the drawing paper can be regarded as a Cartesian coordinate system, and initially, all points on it is white.
Baby Volcano plans to paint the drawing paper in n
Let P
Input
The first line contains a single integer t(1≤t≤100)
, the number of testcases.
For each testcase, the first line contains a single integer n(1≤n≤2×10
5
)
, the number of steps
Then n
lines follow. Each line contains 3
integers l
i
,r
i
,h
i
(1≤l
i
,<r
i
≤10
9
,1≤h
i
≤10
9
)
.
The input guarantees that there are no more than 3
testcases with n>1000
.
For each testcase, the first line contains a single integer n(1≤n≤2×10
Then n
The input guarantees that there are no more than 3
Output
For each testcase, output n
lines. Each line contains a single integer, representing the perimeter of black area after the first i
steps.
Sample Input
1
6
1 2 2
3 4 3
5 6 2 、
1 4 1
2 6 1
3 7 4
Sample Output
6
题意:这门课是关于艺术的。毕加索先生给每个婴儿一张白色的画纸,让他们在上面画画。小火山要把画纸涂成黑色。为了方便起见,可以把图纸看成是笛卡尔坐标系,最初,图纸上的所有点都是白色的。小火山计划在n步骤画图纸。在第i步中,他将矩形Ri涂成黑色,其中Ri左下角为(li,0), Ri右上角为(ri,hi)。在第一个i步骤之后,您的任务是计算Pi上黑色区域的周长。输入第一行包含单个整数t(1<= t <=100),测试用例的数量。对于每个t,第一行包含单个整数n(1 <=n<= 2* 10^5),即步骤数。然后接下来n行。每一行包含3个整数li,ri,hi(1≤l
i
,<r
i
≤10^9
,1≤h
i
≤10^
9
)
.。输入保证测试用例不超过3个大于1000的n值. 输出每个测试用例,输出n行。每行包含一个整数,表示第一个步骤i之后的黑色区域的周长。
题解:离散化之后,这题等价于两个操作:
1.区间取max
2.计算(2*非0的区间长度和)+![]()
答案前半部分是个区间覆盖,我们只需要考虑后半部分
操作1可以用segment tree beats 转化成对区间内的最小值集体增加一个数的操作,且这次操作不会让区间最小值变得比严格次小值更大
唯一的问题在于怎么进行区间最小值修改的同时,更新区间内
这个只需要维护区间内的最小值的段数,或者更具体得维护有多少个间隔满足ai,ai+1中恰好只有一个是区间最小值。假设这样的间隔有k个,那么一次对最小值加a的操作会让答案减少ak,这样就可以维护了
{ int mi,miv,mi1; int la,L,R; LL v; }b[N*4]; void build(int l=1,int r=m,int e=1) { b[e].mi=0,b[e].miv=0,b[e].mi1=INF; b[e].la=b[e].L=b[e].R=0; b[e].v=0; trz[e]=tr0[e]=0; if(l==r)return; int mid=(l+r)>>1; build(l,mid,e<<1); build(mid+1,r,e<<1|1); } void changet(int l1,int r1,int l=1,int r=m,int e=1) { if(trz[e])return; if(l1<=l&&r<=r1) { trz[e]=1; tr0[e]=zx[r+1]-zx[l]; return; } int mid=(l+r)>>1; if(l1<=mid)changet(l1,r1,l,mid,e<<1); if(mid<r1)changet(l1,r1,mid+1,r,e<<1|1); tr0[e]=tr0[e<<1]+tr0[e<<1|1]; if(tr0[e]==zx[r+1]-zx[l])trz[e]=1; } void PD(int l,int r,int e) { if(b[e].la<=b[e].mi)return; b[e].v-=(LL)(b[e].la-b[e].mi)*b[e].miv; b[e].mi=b[e].la; b[e].L=max(b[e].L,b[e].la); b[e].R=max(b[e].R,b[e].la); if(l!=r) { b[e<<1].la=max(b[e<<1].la,b[e].la); b[e<<1|1].la=max(b[e<<1|1].la,b[e].la); } b[e].la=0; } void merge(int e) { b[e].v=b[e<<1].v+b[e<<1|1].v+abs(b[e<<1].R-b[e<<1|1].L); b[e].L=b[e<<1].L;b[e].R=b[e<<1|1].R; b[e].mi=b[e<<1|1].mi,b[e].miv=b[e<<1|1].miv,b[e].mi1=b[e<<1|1].mi1; if(b[e<<1].mi==b[e].mi) { b[e].miv+=b[e<<1].miv; b[e].mi1=min(b[e].mi1,b[e<<1].mi1); }else if(b[e<<1].mi>b[e].mi) { b[e].mi1=min(b[e].mi1,b[e<<1].mi); }else if(b[e<<1].mi<b[e].mi) { b[e].mi=b[e<<1].mi; b[e].miv=b[e<<1].miv; b[e].mi1=min(b[e<<1].mi1,b[e<<1|1].mi); } if((b[e<<1].R==b[e].mi)^(b[e<<1|1].L==b[e].mi))++b[e].miv; } void change(int l1,int r1,int l2,int l=1,int r=m,int e=1) { if(b[e].mi>=l2)return; if(l1<=l&&r<=r1&&b[e].mi1>l2) { b[e].la=l2; PD(l,r,e); return; } int mid=(l+r)>>1; PD(l,mid,e<<1);PD(mid+1,r,e<<1|1); if(l1<=mid)change(l1,r1,l2,l,mid,e<<1); if(mid<r1)change(l1,r1,l2,mid+1,r,e<<1|1); merge(e); } void PAO(int l=1,int r=m,int e=1) { PD(l,r,e); if(l==r)return; int mid=(l+r)>>1; PAO(l,mid,e<<1); PAO(mid+1,r,e<<1|1); int t=b[e].v; merge(e); } int main() { int q,w,_; read(_); while(_--) { read(n); p[0]=0; fo(i,1,n)read(a[i][0]),read(a[i][1]),read(a[i][2]),p[++p[0]]=a[i][0],p[++p[0]]=a[i][1]; sort(p+1,p+1+p[0]); p[0]=unique(p+1,p+1+p[0])-p-1; m=p[0]-1; fo(i,1,p[0])zx[i]=p[i]; fo(i,1,n) { q=lower_bound(p+1,p+1+p[0],a[i][0])-p; w=lower_bound(p+1,p+1+p[0],a[i][1])-p; a[i][0]=q; a[i][1]=w-1; } build(); fo(i,1,n) { // PAO(); int L=a[i][0],R=a[i][1]; changet(L,R); ans=tr0[1]*2LL; // printf("%d ",ans); change(L,R,a[i][2]); ans+=b[1].v+b[1].L+b[1].R; printf("%lld\n",ans); } } return 0; }
1002.Graph Theory Class
Problem Description
This class is on graph theory. Mr. Kruskal teaches babies the concept of minimal spanning tree, and how to calculate the minimal spanning tree of a given graph.
Now, it's time for an in-class quizz. Mr. Kruskal shows a special graph G
: G
is a complete undirected graph with n
vertices, and vertices in G
are indexed from 1
to n
. The weight of the edge between the i
th vertex and the j
th vertex is equal to lcm(i+1,j+1)
. Babies are asked to find the minimal spanning tree of G
.
As a super baby, Baby Volcano quickly finds an answer, but he is not sure on the correctness of his answer. Your task is to tell Baby Volcano the weight sum of all edges on the minimal spanning tree, so that he could verify his answer.
Given two positive integers, lcm(i,j)
is defined as the minimal positive integer k
satisfying both i
and j
are factors of k
.
Now, it's time for an in-class quizz. Mr. Kruskal shows a special graph G
As a super baby, Baby Volcano quickly finds an answer, but he is not sure on the correctness of his answer. Your task is to tell Baby Volcano the weight sum of all edges on the minimal spanning tree, so that he could verify his answer.
Given two positive integers, lcm(i,j)
Input
The first line contains a single integer t(1≤t≤50)
, the number of testcases.
For each testcase, the first line contains two integers n,K(1≤n≤10
10
,10
8
≤K≤10
9
)
.
The input guarantees that K
is a prime number。
The input guarantees that there are no more than 5
testcases with n>10
9![]()
.
For each testcase, the first line contains two integers n,K(1≤n≤10
The input guarantees that K
The input guarantees that there are no more than 5
Output
For each testcase, output a single line with a single integer, the answer module K
.
Sample Input
3
3 998244353
100 998244353
1000000000 998244353
Sample Output
10
6307
192026508
题意:这门课是关于图论的。Kruskal教授孩子们最小生成树的概念,以及如何计算给定图的最小生成树。现在是课堂小测验的时间了。Kruskal先生给出了一个特殊的图G: G是一个带有n个顶点的完全无向图,G中的顶点从1到n建立了索引。第ith个顶点和第jth个顶点之间的边权等于lcm(i+1,j+1)。孩子们被要求找到G的最小生成树,火山宝宝作为一个超级宝宝,很快就找到了答案,但他对自己的答案的正确性并不确定。你的任务是告诉Baby Volcano最小生成树上所有边的重量总和,以便他可以验证他的答案。给定两个正整数,lcm(i,j)定义为同时满足i和j为k因子的最小正整数k。输入第一行包含单个整数t(1 <=t<= 50),测试用例的数量。对于每个t,第一行包含两个整数n,K(1<= n<= 10^10,10^8 <=K <=10^9。输入保证K是一个素数。输入保证不超过5个测试用例10 ^ 9。对于每个测试用例的输出,输出一行带有单个整数的答案模块K。
方法:考虑一个结构,对于3<=i<=n,如果i是质数,则加上边(2,i),如果i是合数,则加上边(d,i),其中d是i的某个不等于1,i的约数。现在得到的结果是生成一棵树,同时因为选择的所有边都是i的最小边,所以这棵树一定是最小生成树。一次可以得到答案为
中的质数和。
中的质数和。质数和可以用分段打表、各种数论筛法来求
#include <iostream> #include <cmath> #include <vector> using namespace std; int t; long long n,k; long long f2(long long v, long long n, long long ndres, long long len) { if(v>=ndres) return (n/v-1); else return len-v; } long long f(long long n) { long long res=(long long)sqrt(n); long long ndres =n/res; long long len =res+ndres-1; vector<long long> A(len+1); vector<long long> B(len+1); for(long long i=0;i<res;i++) { B[i]=n/(i+1); } for(long long i=res;i<len;i++) { B[i]=B[i-1]-1; } for(long long i=0;i<len;i++) { long long tmp=B[i]+1; A[i]=tmp*(tmp-1)/2-1; } for(long long p=2;p<=res;p++) { long long tmp=len-p; if(A[tmp]>A[tmp+1]) { long long sp =A[tmp+1]; long long p2 =p*p; for(long long i=0;i<len;i++) { if(B[i]>=p2) { long long t=f2(B[i]/p,n,ndres,len); A[i]=A[i]-p*(A[t]-sp); } else break; } } } return max(0LL, A[0]-2); } long long qp(long long a, long long b) { long long res = 1; while (b) { if (b & 1LL) res = res * a % k; a = a * a % k; b >>= 1LL; } return res; } int main(void) { cin>>t; while(t--) { cin>>n>>k; // if(n==1) cout<<0<<endl; // else if(n==2) cout<<6<<endl; // else{ long long ans=((n+4)%k*(n-1)%k*qp(2,k-2)%k+(f(n+1)%k))%k; cout<<ans<<endl; // } } return 0; }
1004.Chess Class
Problem Description
This class is on chess. Baby Volcano is playing a special chess game with his friend, Baby Evil.
In this chess game, there is a directed graph G=(V,E)
. Vertices are indexed from 1
to n
. It is guaranteed that every vertex has at least one out-going edge, i.e. ∀v∈V,∃w∈V,(v,w)∈E
, Baby Volcano takes control of a subset of vertices X⊆V
, Baby Evil takes control of V∖X
. Every vertex v
is assigned a weight W(v)
.
There is a chess, positioning at s∈V
initially. The game consists of three phases.
1. For every p∈X
, Baby Volcano chooses an out-going edge (p,q)∈E
and delete other out-going edges of vertex p
.
2. After Volcano's operation, Baby Evil would similarly choose an out-going edge (p
′
,q
′
)∈E
and delete other out-going edges of p
′![]()
for every p
′
∉X
. Both two babies make decisions based on chess's initial position s
.
3. After two processes above, every vertex would remain only one out-going edge. The chess starts moving along the unique path in the processed graph, resulting in an infinite path L=v
0
v
1
v
2
⋯
, where v
0
=s
. Baby Volcano gains score CV
at last, which is computed below:
, while Baby Evil wants to minimize it.
Your task is to determine, for every s,1≤s≤n
, compute CV
under the circumstance that the chess is put at s
initially.
In this chess game, there is a directed graph G=(V,E)
There is a chess, positioning at s∈V
1. For every p∈X
2. After Volcano's operation, Baby Evil would similarly choose an out-going edge (p
3. After two processes above, every vertex would remain only one out-going edge. The chess starts moving along the unique path in the processed graph, resulting in an infinite path L=v
CV:=max{W(v
i
) | v
i
appears in L}![]()
Baby Volcano wants to maximize CVYour task is to determine, for every s,1≤s≤n
Input
In the first line there is a number T
, denotes the number of test cases.
Then there are T
parts of input, each part describes a test case. Each parts begins with n,m,R,B
, denotes the number of vertices, edges, the range of W(v)
, and the size of X
, the set which baby volcano takes control.
Then there is a line consists of B
numbers, denotes elements in X
.
Then there is a line with n
numbers, the i
-th number, denotes W(i),1≤W(i)≤R
.
Then there are m
lines, each line consists of 2
numbers, u,v
, showing that there is an edge from u
to v
in G
.
1≤T≤100
1≤m,R≤5×10
5![]()
1≤B≤n≤5×10
5![]()
1≤∑n,∑m,∑R≤10
6![]()
Then there are T
Then there is a line consists of B
Then there is a line with n
Then there are m
1≤T≤100
1≤m,R≤5×10
1≤B≤n≤5×10
1≤∑n,∑m,∑R≤10
Output
For each test case, you should first output ''Case #t:''(without quotes), denotes the test number.
Then you need to output n
numbers in the next line, the i
-th number is CV
under the circumstance that the chess is put at i
initially.
Then you need to output n
Sample Input
2
3 3 2 1
3
1 1 2
1 2
2 3
3 3
4 6 10 1
4
8 7 3 2
1 3
2 4
3 2
4 2
2 1
2 2
Sample Output
Case #1:
2 2 2
Case #2:
8 7 7 7
题意:这门课是关于国际象棋的。火山宝宝正在和他的朋友恶魔宝宝玩一种特殊的象棋游戏。在这个象棋游戏中,有一个有向图G=(V,E)。顶点从1到n建立索引。是保证每一个顶点都有至少一个导出边缘,即
婴儿火山需要控制顶点的一个子集
婴儿邪恶控制V/X每个顶点v分配重量w (v) 。有一个国际象棋,最初定位在![]()
婴儿火山需要控制顶点的一个子集
婴儿邪恶控制V/X每个顶点v分配重量w (v) 。有一个国际象棋,最初定位在
。这个游戏由三个阶段组成。1. 对于X中的每条pxp \,小火山选择E中的一条外出边(p,q) E(p,q)\,并删除顶点pp的其他外出边。火山行动之后,小恶魔同样会在E中选择一条外出边(p,q) E(p',q'),并删除每条p' Xp'的外出边(p',q')。两个小恶魔都会根据象棋的初始位置ss. 3做出决定。经过上述两个过程后,每个顶点将只剩下一条向外的边。象棋开始沿着被处理的图中的唯一路径移动,产生一个无限路径L=v0v1v2,其中v0=s。最后火山宝宝获得CV分数,计算如下:CV:=max{W(vi) | vi出现在L} 火山宝宝想最大化CV,而恶魔宝宝想最小化CV。你的任务是确定,对于每一个s,(1 <=s <=n),计算在国际象棋初始放置在s的情况下的CV。输入的第一行有一个数字T,表示测试用例的数量。然后是输入的T部分,每个部分描述一个测试用例。每个部分从n,m,R,B开始,表示顶点、边的数量,W(v)的范围,以及小火山控制的集合X的大小。然后有一行由B号组成,表示X中的元素。与神经网络的数字还有一条线,i-th数字,表示W (i), 1 <=W (i)<= R .还有m行,每一行包含2个数字,u, v显示有一个边缘从u在G v。1<= T<= 100,1<=m ,R<= 5 *10^5 ,![]()
输出为每个测试用例,您应该首先输出”案例# T:“(没有引号),为测试号。然后你需要在下一行输出n数字,第i号数字是CV情况下,国际象棋是在 i 最初。

输出为每个测试用例,您应该首先输出”案例# T:“(没有引号),为测试号。然后你需要在下一行输出n数字,第i号数字是CV情况下,国际象棋是在 i 最初。
题解:定义:Vi表示权值第i大的节点,Ki表示vi的权值;Li表示权值最大的i个节点构成的集合,L0=空集;对于集合A,W(A)表示所有的起点s,使得baby volcano有一个必胜的策略可以让棋子经过A,我们要求的就是对每一个顶点s找到最小的i使得
并输出Ki然后我们从小到大依次枚举i,通过W(Li-1)来计算W(Li),首先对于i=0,显然W(L0)=空集,然后如果W(Li-1)已经算出来了,那么首先令W(Li)相对于W(Li-1)多出来的节点,广搜就是从Vi出发在反图上搜索,对于一个baby evil的节点,必须要他所有的出边都属于W(Li),他才属于W(Li).
并输出Ki然后我们从小到大依次枚举i,通过W(Li-1)来计算W(Li),首先对于i=0,显然W(L0)=空集,然后如果W(Li-1)已经算出来了,那么首先令W(Li)相对于W(Li-1)多出来的节点,广搜就是从Vi出发在反图上搜索,对于一个baby evil的节点,必须要他所有的出边都属于W(Li),他才属于W(Li).
#include<bits/stdc++.h> #define N 500010 using namespace std; inline int read() { int x=0,f=1; char c=getchar(); while ( c<'0' || c>'9') {if (c=='-') f=-1; c=getchar();} while (c>='0' && c<='9') x=x*10+c-'0',c=getchar(); return x*f; } int eu[N],eb[N],ev[N],edn; void addedge(int u,int v) { eb[++edn]=eu[v]; eu[v]=edn; ev[edn]=u; } int n,m,R,B; int W[N],OP[N],dp[N],cd[N]; bool vis[N]; deque<int>q; void init() { memset(OP,0,sizeof(OP)); memset(cd,0,sizeof(cd)); memset(vis,0,sizeof(vis)); memset(dp,0,sizeof(dp)); edn=-1; memset(eu,-1,sizeof(eu)); } struct data { int w,i; bool operator < (const data &a) const { return w>a.w; } }mx[N]; void dfs(int u) { vis[u]=1; for(int i=eu[u];i!=-1;i=eb[i]) { int v=ev[i]; if (vis[v]) continue; if (OP[v]==1) { dp[v]=dp[u]; dfs(v); } else { --cd[v]; if (!cd[v]) { dp[v]=dp[u]; dfs(v); } } } } int main() { int T=read(),Case=1; while (T--) { init(); n=read(),m=read(),R=read(),B=read(); for (int i=1;i<=B;i++) { int x=read(); OP[x]=1; } for (int i=1;i<=n;i++) { W[i]=read(); dp[i]=W[i]; mx[i]=((data){W[i],i}); } sort(mx+1,mx+1+n); for (int i=1;i<=m;i++) { int u=read(),v=read(); cd[u]++; addedge(u,v); } for(int i=1;i<=n;i++) if (!vis[mx[i].i]) dfs(mx[i].i); printf("Case #%d:\n",Case++); for (int i=1;i<n;i++) printf("%d ",dp[i]); printf("%d\n",dp[n]); }
1005.Lunch
Problem Description
Now it's time for lunch. Today's menu is chocolate!
Though every baby likes chocolate, the appetites of babies are little. After lunch, there are still n
pieces of chocolate remained: The length of the i
th piece is l
i![]()
.
Using the remained chocolate, Baby Volcano is going to play a game with his teacher, Mr. Sprague. The rule of the game is quite simple.
Two player plays in turns, and Baby Volcano will play first:
1. In each turn, the player needs to select one piece of chocolate. If the length of the selected piece is equal to 1
, the player of this turn will lose immediately.
2. Suppose the length of the selected piece is l
. Then the player needs to select a positive integer k
satisfying k
is at least 2
and k
is a factor of l
.
3. Then the player needs to cut the selected piece into k
pieces with length l
k![]()
![]()
.
The game continues until one player selects a piece of chocolate with length 1
.
Suppose both players plays optimally, your task is to determine whether Baby Volcano will win.
Though every baby likes chocolate, the appetites of babies are little. After lunch, there are still n
Using the remained chocolate, Baby Volcano is going to play a game with his teacher, Mr. Sprague. The rule of the game is quite simple.
Two player plays in turns, and Baby Volcano will play first:
1. In each turn, the player needs to select one piece of chocolate. If the length of the selected piece is equal to 1
2. Suppose the length of the selected piece is l
3. Then the player needs to cut the selected piece into k
The game continues until one player selects a piece of chocolate with length 1
Suppose both players plays optimally, your task is to determine whether Baby Volcano will win.
Input
The first line contains single integer t(1≤t≤2∗10
4
)
, the number of testcases.
For each testcase, the first line contains a single integer n(1≤n≤10)
.
The second line contains n
positive integers l
i
(1≤l
i
≤10
9
)
, representing the length of each piece.
For each testcase, the first line contains a single integer n(1≤n≤10)
The second line contains n
Output
For each testcase, output char 'W' if Baby Volcano will win, otherwise output char 'L'.
Sample Input
3
2
4 9
2
2 3
3
3 9 27
Sample Output
W
L
L
题意:小火山与他老师轮流玩游戏,小火山先开始1。在每个回合中,玩家需要选择一块巧克力。如果所选棋子的长度等于1,则该回合的玩家将立即输掉。2. 假设所选部分的长度是l。然后玩家需要选择一个正整数k满足k至少是2并且k是l的一个因子。3.然后玩家需要将所选片段切割成长度为1/k的k个片段。游戏继续进行,直到其中一名玩家选择一块长度为1的巧克力。假设两个玩家都玩得最优,你的任务是确定火山宝宝是否会赢。输入第一行包含单个整数t(1<= t<= 2 *10^4),测试用例的数量。对于每个t,第一行包含单个整数n(1 <=n<= 10)。第二行包含n个正整数li(1 <=li <=10^9),表示每一段的长度。对于每个t,如果Baby Volcano赢了,输出 'W',否则输出 'L'
题解:这是一个nim游戏,所以只需要知道数字k的nim函数f(k)就可以了,
结论:f(k)等于k的奇质因子个数+[k为偶数],只要对着归纳就可以了,
#include<bits/stdc++.h> using namespace std; const int maxn = 2e7+10; int N[maxn]; int p[maxn]; int cnt; void sha(){ N[1] = 1; for(int i = 2;i <= 2e7;i++){ if(!N[i]){ p[++cnt] = i; } for(int j = 1;j <= cnt;j++){ if(i * p[j] > 2e7){ break; } N[i*p[j]] =1; if(i % p[j] == 0){ break; } } } } int SG(int x) { int cur = x; int ans = 0; if(x%2 == 0){ ans ++; while(x%2 == 0){ x /= 2; } } for(int i = 2;i <= cnt;i++){ if(p[i] > x) break; if(p[i] > sqrt(cur) ){ return ans+1; } if(x % p[i] == 0){ while(x%p[i] == 0){ ans++; x/=p[i]; } if(x==1){ break; } } } return ans; } int main(){ sha(); // ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T; cin>>T; while(T--){ int ans = 0; int n; cin >> n; for(int i = 1;i <= n;i++){ int x ; cin>>x; ans = (ans ^ SG(x)); } if(ans == 0){ cout << "L" << '\n'; }else { cout << "W" << '\n'; } } return 0; }

浙公网安备 33010602011771号