题解(652.div2)

题解(652.div2)

A:FashionabLee

Lee is going to fashionably decorate his house for a party, using some regular convex polygons…
Lee thinks a regular nn-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the OX-axis and at least one of its edges is parallel to the OY-axis at the same time.
Recall that a regular nn-sided polygon is a convex polygon with nn vertices such that all the edges and angles are equal.
Now he is shopping: the market has tt regular polygons. For each of them print YES if it is beautiful and NO otherwise.
Input
The first line contains a single integer tt (1≤t≤104) — the number of polygons in the market.
Each of the next t lines contains a single integer ni (3≤ni≤109): it means that the i-th polygon is a regular ni-sided polygon.
Output
For each polygon, print YES if it’s beautiful or NO otherwise (case insensitive).

很简单的一个数学题,不多介绍。

#include<bits/stdc++.h>
#define LL long long
#define U unsigned
bool isp(int x){
	if(x<2)return 0;
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0) return 0;
	}
	return 1;
}
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
using namespace std;
int main(){
	int T=read();
	while(T--){
		if(read()%4==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	} 
    return 0;
}


B:AccurateLee

Lee was cleaning his house for the party when he found a messy string under the carpets. Now he’d like to make it clean accurately and in a stylish way…
The string s he found is a binary string of length n (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters si and si+1, and if sisi is 1 and si+1 is 0, he can erase exactly one of them (he can choose which one to erase but he can’t erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he’d like to make the string s as clean as possible. He thinks for two different strings x and y, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer t test cases: for the i-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings x and y of the same length then x is lexicographically smaller than y if there is a position i such that x1=y1, xi−1=yi−1 and xi<yi.
Input
The first line contains the integer t (1≤t≤104) — the number of test cases.
Next 2t lines contain test cases — one per two lines.
The first line of each test case contains the integer nn (1≤n≤105) — the length of the string s.
The second line contains the binary string s. The string s is a string of length n which consists only of zeroes and ones.
It’s guaranteed that sum of n over test cases doesn’t exceed 105.
Output
Print t answers — one per test case.
The answer to the i-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).

同样是一个简单的数学题,是计算10数量并且算法计算。

#include<bits/stdc++.h>
#define LL long long
#define U unsigned
bool isp(int x){
	if(x<2)return 0;
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0) return 0;
	}
	return 1;
}
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
using namespace std;
char s[150000];
int main(){
	int T=read();
	while(T--){
		int n=read(),ze=0,ons=0x7f7f7f7f;
		cin>>s;
		for(int i=0;i<n;i++)s[i]=='0'?ze=max(ze,i):ons=min(ons,i);
		if(ons>=ze){
			cout<<s<<endl;
		}else{
			for(int i=0;i<ons;i++)cout<<s[i];
			for(int i=ze;i<n;i++)cout<<s[i];
			cout<<endl;
		}
		
	} 
	return 0;
}





C:RationalLee

Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought n integers, now it’s time to distribute them between his friends rationally…
Lee has n integers a1,a2,…,an in his backpack and he has k friends. Lee would like to distribute all integers in his backpack between his friends, such that the i-th friend will get exactly wi integers and each integer will be handed over to exactly one friend.
Let’s define the happiness of a friend as the sum of the maximum and the minimum integer he’ll get.
Lee would like to make his friends as happy as possible, in other words, he’d like to maximize the sum of friends’ happiness. Now he asks you to calculate the maximum sum of friends’ happiness.
Input
The first line contains one integer t (1≤t≤104) — the number of test cases.
Next 3t lines contain test cases — one per three lines.
The first line of each test case contains two integers n and k (1≤n≤2⋅105; 1≤k≤n) — the number of integers Lee has and the number of Lee’s friends.
The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109) — the integers Lee has.
The third line contains k integers w1,w2,…,wk (1≤wi≤n; w1+w2+…+wk=n) — the number of integers Lee wants to give to each friend.
It’s guaranteed that the sum of n over test cases is less than or equal to 2⋅105.
Output
For each test case, print a single integer — the maximum sum of happiness Lee can achieve.

这道题是一道数学题。需要考生现场制造算法。

#include<bits/stdc++.h>
#define LL long long
#define U unsigned
bool isp(LL x){
	if(x<2)return 0;
	for(LL i=2;i<=sqrt(x);i++){
		if(x%i==0) return 0;
	}
	return 1;
}
inline LL read()
{
	LL x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
using namespace std;
LL a[300000],w[300000];
int main(){
	LL T=read();
	while(T--){
		LL n=read(),k=read(),ans=0;
		for(LL i=0;i<n;i++){
			a[i]=read();
		}
		for(LL i=0;i<k;i++){
			w[i]=read();
		}
		sort(a,a+n);
		sort(w,w+k);
		for(LL i=k-1,j=0;i>=0;i--){
			if(j>=n-k)break;
			ans+=a[j];
			j+=w[i]-1;
		}
		for(LL i=n-1,j=0;i>=n-k;i--,j++){
			ans+=a[i];
			if(w[j]==1)ans+=a[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

D:TediousLee

Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn’t feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes…
Let’s define a Rooted Dead Bush (RDB) of level n as a rooted tree constructed as described below.
A rooted dead bush of level 1 is a single vertex. To construct an RDB of level i we, at first, construct an RDB of level i−1, then for each vertex u:
if u has no children then we will add a single child to it;
if u has one child then we will add two children to it;
if u has more than one child, then we will skip it.
Let’s define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw:
Lee has a Rooted Dead Bush of level n. Initially, all vertices of his RDB are green.
In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw’s vertices in yellow.
He’d like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo 1000000007.
Input
The first line contains one integer t(1≤t≤10000) — the number of test cases.
Next t lines contain test cases — one per line.
The first line of each test case contains one integer n (1≤n≤2000000) — the level of Lee’s RDB.
Output
For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo 1000000007.

这道题是一道动规题,方程为dp[i]=(dp[i-1]+2*dp[i-2])。

#include<bits/stdc++.h>
#define LL long long
#define U unsigned
bool isp(LL x){
	if(x<2)return 0;
	for(LL i=2;i<=sqrt(x);i++){
		if(x%i==0) return 0;
	}
	return 1;
}
inline LL read()
{
	LL x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
using namespace std;
LL ans[3000000];
int main(){
	LL T=read();
	for(LL i=3;i<2100000;i++){
		dp[i]=(dp[i-1]+2*dp[i-2])%1000000007;
		if(i%3==0){
			dp[i]=(dp[i]+4)%1000000007;
		}
	}
	while(T--){
		cout<<dp[read()]<<endl;
	}
	return 0;
}



E:DeadLee

Lee bought some food for dinner time, but Lee’s friends eat dinner in a deadly way. Lee is so scared, he doesn’t want to die, at least not before seeing Online IOI 2020…
There are nn different types of food and mm Lee’s best friends. Lee has wiwi plates of the i-th type of food and each friend has two different favorite types of food: the ii-th friend’s favorite types of food are xi and yi (xi≠yi).
Lee will start calling his friends one by one. Whoever is called will go to the kitchen and will try to eat one plate of each of his favorite food types. Each of the friends will go to the kitchen exactly once.
The only problem is the following: if a friend will eat at least one plate of food (in total) then he will be harmless. But if there is nothing left for him to eat (neither xi nor yi), he will eat Lee instead ×_×.
Lee can choose the order of friends to call, so he’d like to determine if he can survive dinner or not. Also, he’d like to know the order itself.
Input
The first line contains two integers n and m (2≤n≤100000; 1≤m≤2⋅100000) — the number of different food types and the number of Lee’s friends.
The second line contains n integers w1,w2,…,wn (0≤wi≤1000000) — the number of plates of each food type.
The i-th line of the next mm lines contains two integers xi and yi (1≤xi,yi≤n; xi≠yi) — the favorite types of food of the i-th friend.
Output
If Lee can survive the dinner then print ALIVE (case insensitive), otherwise print DEAD (case insensitive).
Also, if he can survive the dinner, print the order Lee should call friends. If there are multiple valid orders, print any of them.

这道题是一道图论题,同时也需要结合数学推导算法。

#include<bits/stdc++.h>
#define LL long long
#define U unsigned
bool isp(int x){
	if(x<2)return 0;
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0) return 0;
	}
	return 1;
}
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
using namespace std;
int n=read(),m=read(),x,y,w[200000],b[200000],del[200000];
vector<pair<int,int> >g[200000];
int q[200000],r;
int main(){
	for(int i=1;i<=n;i++){
		w[i]=read();
	}
	for(int i=1;i<=m;i++){
		int x=read(),y=read();
		b[x]++,b[y]++;
		g[x].push_back(pair<int,int>(y,i));
		g[y].push_back(pair<int,int>(x,i));
	}
	for(int i=1;i<=n;i++){
		if(w[i]>=b[i]){
			q[r++]=i;
		}
	}
	for(int i=0;i<r;i++){
		int x=q[i];
		del[x]=i;
		for(pair<int,int> y:g[x]){
			int tmp=y.first;
			if(w[tmp]>=b[tmp])continue;
			if(--b[tmp]==w[tmp]){
				q[r++]=tmp;
			}
		}
	}
	if(r!=n){
		cout<<"DEAD"<<endl;
	}else{
		cout<<"ALIVE"<<endl;
		for(int i=n-1;i>=0;i--){
			int x=q[i];
			for(pair<int,int> y:g[x]){
				if(del[y.first]>i){
					cout<<y.second<<" ";
				}
			}
		}
	}
	return 0;
}

F:BareLee

Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called “Critic”…
The game is a one versus one game. It has tt rounds, each round has two integers sisi and eiei (which are determined and are known before the game begins, sisi and eiei may differ from round to round). The integer sisi is written on the board at the beginning of the corresponding round.
The players will take turns. Each player will erase the number on the board (let’s say it was a) and will choose to write either 2⋅a or a+1 instead. Whoever writes a number strictly greater than eiei loses that round and the other one wins that round.
Now Lee wants to play “Critic” against Ice Bear, for each round he has chosen the round’s sisi and eiei in advance. Lee will start the first round, the loser of each round will start the next round.
The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game.
Determine if Lee can be the winner independent of Ice Bear’s moves or not. Also, determine if Lee can be the loser independent of Ice Bear’s moves or not.
Input
The first line contains the integer tt (1≤t≤105) — the number of rounds the game has.
Then tt lines follow, each contains two integers si and ei (1≤si≤ei≤1018) — the i-th round’s information.
The rounds are played in the same order as given in input, si and ei for all rounds are known to everyone before the game starts.
Output
Print two integers.
The first one should be 1 if Lee can be the winner independent of Ice Bear’s moves, and 0 otherwise.
The second one should be 1 if Lee can be the loser independent of Ice Bear’s moves, and 0 otherwise.

这道题是一道博弈题,但是因为它不是模板题,这需要结合一些考生现场自创的数学算法。

#include<bits/stdc++.h>
#define LL long long
#define U unsigned
bool isp(int x){
	if(x<2)return 0;
	for(int i=2;i<=sqrt(x);i++){
		if(x%i==0) return 0;
	}
	return 1;
}
inline LL read()
{
	LL x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
using namespace std;
LL win(LL x,LL y){
	if(y&1){
		if(x&1)return 0;
		return 1;
	}else if(x>y/2){
		if(x&1)return 1;
		return 0;
	}else if(x>y/4)return 1;
	else return win(x,y/4);
}
LL lose(LL x,LL y){
	if(x>y/2) return 1;
	else return win(x,y/2);
}
LL s[300000],e[300000];
int main(){
	LL t=read(),w,l;
	for(LL i=1;i<=t;i++)s[i]=read(),e[i]=read();
	for(LL i=1,now=0;i<=t;i++){
		w=win(s[i],e[i])^now;
		l=lose(s[i],e[i])^now;
		if(w==l)break;
		if(w)now=1;
		else now=0;
	}
	cout<<w<<" "<<l;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值