Codeforces Global Round 4(ABCDE)

Prime Minister CodeForces - 1178A
Alice is the leader of the State Refactoring Party, and she is about to become the prime minister.

The elections have just taken place. There are n parties, numbered from 1 to n. The i-th party has received ai seats in the parliament.

Alice’s party has number 1. In order to become the prime minister, she needs to build a coalition, consisting of her party and possibly some other parties. There are two conditions she needs to fulfil:

The total number of seats of all parties in the coalition must be a strict majority of all the seats, i.e. it must have strictly more than half of the seats. For example, if the parliament has 200 (or 201) seats, then the majority is 101 or more seats.
Alice’s party must have at least 2 times more seats than any other party in the coalition. For example, to invite a party with 50 seats, Alice’s party must have at least 100 seats.
For example, if n=4 and a=[51,25,99,25] (note that Alice’a party has 51 seats), then the following set [a1=51,a2=25,a4=25] can create a coalition since both conditions will be satisfied. However, the following sets will not create a coalition:

[a2=25,a3=99,a4=25] since Alice’s party is not there;
[a1=51,a2=25] since coalition should have a strict majority;
[a1=51,a2=25,a3=99] since Alice’s party should have at least 2 times more seats than any other party in the coalition.
Alice does not have to minimise the number of parties in a coalition. If she wants, she can invite as many parties as she wants (as long as the conditions are satisfied). If Alice’s party has enough people to create a coalition on her own, she can invite no parties.

Note that Alice can either invite a party as a whole or not at all. It is not possible to invite only some of the deputies (seats) from another party. In other words, if Alice invites a party, she invites all its deputies.

Find and print any suitable coalition.

Input
The first line contains a single integer n (2≤n≤100) — the number of parties.

The second line contains n space separated integers a1,a2,…,an (1≤ai≤100) — the number of seats the i-th party has.

Output
If no coalition satisfying both conditions is possible, output a single line with an integer 0.

Otherwise, suppose there are k (1≤k≤n) parties in the coalition (Alice does not have to minimise the number of parties in a coalition), and their indices are c1,c2,…,ck (1≤ci≤n). Output two lines, first containing the integer k, and the second the space-separated indices c1,c2,…,ck.

You may print the parties in any order. Alice’s party (number 1) must be on that list. If there are multiple solutions, you may print any of them.

Examples
Input
3
100 50 50
Output
2
1 2
Input
3
80 60 60
Output
0
Input
2
6 5
Output
1
1
Input
4
51 25 99 25
Output
3
1 2 4
Note
In the first example, Alice picks the second party. Note that she can also pick the third party or both of them. However, she cannot become prime minister without any of them, because 100 is not a strict majority out of 200.

In the second example, there is no way of building a majority, as both other parties are too large to become a coalition partner.

In the third example, Alice already has the majority.

The fourth example is described in the problem statement.
题意杀。主要的就是那个人要当首相,她的小弟总数必须大于总数的一半。而且其他的人的小弟的数目必须大于她的一半(大概是酱紫)
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=1e2+10;
int a[maxx];
vector<int> p;
int n;

int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		int sum=0;p.clear();
		for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
		int sum1=a[1];p.push_back(1);
		for(int i=2;i<=n;i++)
		{
			if(sum1*2>sum) break;
			if(a[i]*2<=a[1])
			{
				sum1+=a[i];
				p.push_back(i);
			}
		}
		if(sum1*2<=sum) puts("0");
		else
		{
			cout<<p.size()<<endl;
			for(int i=0;i<p.size();i++) cout<<p[i]<<" ";
			cout<<endl;
		}
	}
}

WOW Factor CodeForces - 1178B
Recall that string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly zero or all) characters. For example, for the string a=“wowwo”, the following strings are subsequences: “wowwo”, “wowo”, “oo”, “wow”, “”, and others, but the following are not subsequences: “owoo”, “owwwo”, “ooo”.

The wow factor of a string is the number of its subsequences equal to the word “wow”. Bob wants to write a string that has a large wow factor. However, the “w” key on his keyboard is broken, so he types two "v"s instead.

Little did he realise that he may have introduced more "w"s than he thought. Consider for instance the string “ww”. Bob would type it as “vvvv”, but this string actually contains three occurrences of “w”:

“vvvv”
“vvvv”
“vvvv”
For example, the wow factor of the word “vvvovvv” equals to four because there are four wows:

“vvvovvv”
“vvvovvv”
“vvvovvv”
“vvvovvv”
Note that the subsequence “vvvovvv” does not count towards the wow factor, as the "v"s have to be consecutive.

For a given string s, compute and output its wow factor. Note that it is not guaranteed that it is possible to get s from another string replacing “w” with “vv”. For example, s can be equal to “vov”.

Input
The input contains a single non-empty string s, consisting only of characters “v” and “o”. The length of s is at most 106.

Output
Output a single integer, the wow factor of s.

Examples
Input
vvvovvv
Output
4
Input
vvovooovovvovoovoovvvvovovvvov
Output
100
Note
The first example is explained in the legend.
统计每个o旁边的vv数目是多少。以前这样的题目不少
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=1e6+100;
char s[maxx];
ll f[maxx],b[maxx];

int main()
{
	while(scanf("%s",s+1)!=EOF)
	{
		int len=strlen(s+1);
		s[len+1]='@';s[0]='@';
		int cnt=0;
		//cout<<s[len]<<endl;
		for(int i=1;i<=len+1;i++)
		{
			f[i]=f[i-1];
			if(s[i]=='v') cnt++;
			else
			{
				f[i]+=cnt?cnt-1:0;
				cnt=0;
			}
		}
		cnt=0;
		for(int i=len;i>=0;i--)
		{
			b[i]=b[i+1];
			if(s[i]=='v') cnt++;
			else 
			{
				b[i]+=cnt?cnt-1:0;
				cnt=0;
			}
		}
		ll ans=0;
		for(int i=1;i<=len;i++) if(s[i]=='o') ans+=f[i]*b[i];
		cout<<ans<<endl;
	}
}

Tiles CodeForces - 1178C
Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below.
在这里插入图片描述

The dimension of this tile is perfect for this kitchen, as he will need exactly w×h tiles without any scraps. That is, the width of the kitchen is w tiles, and the height is h tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black.
在这里插入图片描述
The picture on the left shows one valid tiling of a 3×2 kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts.
Find the number of possible tilings. As this number may be large, output its remainder when divided by 998244353 (a prime number).

Input
The only line contains two space separated integers w, h (1≤w,h≤1000) — the width and height of the kitchen, measured in tiles.

Output
Output a single integer n — the remainder of the number of tilings when divided by 998244353.

Examples
Input
2 2
Output
16
Input
2 4
Output
64
其实就是找规律吧。
左上角的有四种选择,除了这一个其余第一行第一列的都有2种选择。剩下的只有一种选择。。
最后的结果是(2^n-1) * ( 2^m-1)*4。
代码如下:

#include<bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;

ll n,m;

ll qsm(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1) ans=(ans*x)%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}
int main()
{
	while(scanf("%lld%lld",&n,&m)!=EOF)
	{
		printf("%lld\n",(qsm(2L,n-1)*qsm(2L,m-1)%mod)*4L%mod);
	}
}

Prime Graph CodeForces - 1178D
Every person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn’t think of anything inventive. Hence, he will be giving her a graph. How original, Bob! Alice will surely be thrilled!

When building the graph, he needs four conditions to be satisfied:

It must be a simple undirected graph, i.e. without multiple (parallel) edges and self-loops.
The number of vertices must be exactly n — a number he selected. This number is not necessarily prime.
The total number of edges must be prime.
The degree (i.e. the number of edges connected to the vertex) of each vertex must be prime.
Below is an example for n=4. The first graph (left one) is invalid as the degree of vertex 2 (and 4) equals to 1, which is not prime. The second graph (middle one) is invalid as the total number of edges is 4, which is not a prime number. The third graph (right one) is a valid answer for n=4.
在这里插入图片描述

Note that the graph can be disconnected.

Please help Bob to find any such graph!

Input
The input consists of a single integer n (3≤n≤1000) — the number of vertices.

Output
If there is no graph satisfying the conditions, print a single line containing the integer −1.

Otherwise, first print a line containing a prime number m (2≤m≤n(n−1)2) — the number of edges in the graph. Then, print m lines, the i-th of which containing two integers ui, vi (1≤ui,vi≤n) — meaning that there is an edge between vertices ui and vi. The degree of each vertex must be prime. There must be no multiple (parallel) edges or self-loops.

If there are multiple solutions, you may print any of them.

Note that the graph can be disconnected.

Examples
Input
4
Output
5
1 2
1 3
2 3
2 4
3 4
Input
8
Output
13
1 2
1 3
2 3
1 4
2 4
1 5
2 5
1 6
2 6
1 7
1 8
5 8
7 8
Note
The first example was described in the statement.

In the second example, the degrees of vertices are [7,5,2,2,3,2,2,3]. Each of these numbers is prime. Additionally, the number of edges, 13, is also a prime number, hence both conditions are satisfied.
在这里插入图片描述
构造这样的图,每个点的度数和总共的边数是素数。。
首先把素数打表打出来。
我们一开始先把这n个点依次连接起来成为一个环。如果不符合题意的话,在去连任意的两个点。。
这样一定会连起来n+n/2条边,而且每一个点的度数不是2就是3。。有一个规律就是在n到n/2之间肯定会有一个素数。。自己手写一下。所以就没有-1的情况
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=1e5+100;
map<int,bool> mp;
int f[maxx];bool vis[maxx];
int n;

void init()
{
	int flag=0;
	for(int i=2;i<=500005;i++)
	{
		flag=0;mp[i]=0;
		for(int j=2;j<=sqrt(i);j++)
		{
			if(i%j==0) 
			{
				flag=1;
				break;
			}
		}
		if(flag==0) mp[i]=1;
	}
}

int main()
{
	init();
	while(scanf("%d",&n)!=EOF)
	{
		int m;memset(vis,0,sizeof(vis));
		for(m=n;!mp[m];m++);
		cout<<m<<endl;
		for(int i=1;i<=n;i++) cout<<i<<" "<<((i+1)%n?(i+1)%n:n)<<endl;
		m-=n;
		int cnt=1;
		for(int i=1;i<=m;i++)
		{
			while(vis[cnt]) cnt++;
			if(vis[cnt]==0)
			{
				cout<<cnt<<" "<<((cnt+2)%n?(cnt+2)%n:n)<<endl;
				vis[cnt]=vis[((cnt+2)%n?(cnt+2)%n:n)]=1;
			}
		}
	}
}

Archaeology CodeForces - 1178E
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor’s Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it?

The book contains a single string of characters “a”, “b” and “c”. It has been pointed out that no two consecutive characters are the same. It has also been conjectured that the string contains an unusually long subsequence that reads the same from both sides.

Help Alice verify this by finding such subsequence that contains at least half of the characters of the original string, rounded down. Note that you don’t have to maximise the length of it.

A string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters.

Input
The input consists of a single string s (2≤|s|≤106). The string s consists only of characters “a”, “b”, “c”. It is guaranteed that no two consecutive characters are equal.

Output
Output a palindrome t that is a subsequence of s and |t|≥⌊|s|2⌋.

If there are multiple solutions, you may print any of them. You don’t have to maximise the length of t.

If there are no solutions, output a string “IMPOSSIBLE” (quotes for clarity).

Examples
Input
cacbac
Output
aba
Input
abc
Output
a
Input
cbacacacbcbababacbcb
Output
cbaaacbcaaabc
Note
In the first example, other valid answers include “cacac”, “caac”, “aca” and “ccc”.
找出任意的回文子序列。。
题目保证了任意相邻的两个是不一样的。那么任意四个之间会有2个是相同的(抽屉原理)。这样的话肯定是有结果的。那么我们从两头去找这样相同的字符。(l,l+1)(r,r-1)会有两个相同的。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=1e6+100;
string s;
int vis[maxx];

int main()
{
	while(cin>>s)
	{
		int len=s.length();
		memset(vis,0,sizeof(vis));
		int l=0;
		int r=len-1;
		while(l<=r)
		{
			if(l==r)
			{
				vis[l]=1;
				break;
			}
			if(s[l]==s[r]) vis[l]=vis[r]=1;
			else if(s[l]==s[r-1]) vis[l]=vis[r-1]=1;
			else if(s[l+1]==s[r]) vis[l+1]=vis[r]=1;
			else if(s[l+1]==s[r-1]) vis[l+1]=vis[r-1]=1;
			l+=2;r-=2;
		}
		for(int i=0;i<len;i++) if(vis[i]) cout<<s[i];
		cout<<endl;
	}
}

剩下的题不咋会。。。
努力加油a啊,(o)/~

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值