Educational Codeforces Round 34 (Rated for Div. 2)

@ Educational Codeforces Round 34 (Rated for Div. 2)

A. Hungry Student Problem

题目
Ivan’s classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly this amount of chicken.
Formally, Ivan wants to know if he can choose two non-negative integers a and b in such a way that a small portions and b large ones contain exactly x chunks.
Help Ivan to answer this question for several values of x!
其实就是有3和7,用任意个数的3和7,令和为x;

#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;
	cin>>T;
	int n;
	while(T--){
		cin>>n;
		int step=n/3;
		n=n-step*3;
		while(n!=0&&step>=1)
		{
			step--;
			n=n+3;
			if(n%7==0)
			{
				break;
			}
		}
		if(n%7==0)
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
}

B The Modcrab

题目
Vova is again playing some computer game, now an RPG. In the game Vova’s character received a quest: to slay the fearsome monster called Modcrab.

After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h 2 health points and an attack power of a 2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.

Vova’s character has h 1 health points and an attack power of a 1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c 1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c 1 > a 2.

The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a 1) or drink a healing potion (it increases Vova’s health by c 1; Vova’s health can exceed h 1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a 2. The battle ends when Vova’s (or Modcrab’s) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova’s attack.

Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.

Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.
大意
勇者在满足自己死不掉的前提下,出刀,备注(不能超过血量上限)

#include<bits/stdc++.h>
using namespace std;
int m[100005];
int main()
{
	int h,a,c,hh,aa;
	cin>>h>>a>>c>>hh>>aa;
	int sum=0;
	while(hh>0){
		if(hh-a<=0){
			m[sum]=1;
			hh-=a;
		}
		else if(aa>=h){
			m[sum]=0;
			h+=c;
			h-=aa;
		}
		else if(aa<h){
			m[sum]=1;
			hh-=a;
			h-=aa;
		}
		sum++;
	}
	cout<<sum<<endl;
	for(int i=0;i<sum;i++){
		if(m[i]==1){
			cout<<"STRIKE\n";
			continue;
		}
			cout<<"HEAL\n";
	}
}

C Boxes Packing

题目
Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length a i.

Mishka can put a box i into another box j if the following conditions are met:

i-th box is not put into another box;
j-th box doesn’t contain any other boxes;
box i is smaller than box j ( a i < a j).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.

Help Mishka to determine the minimum possible number of visible boxes!

#include<bits/stdc++.h>
using namespace std;map<int,int> q;
int main(){
	int n;
	cin>>n;
	int m=0;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		q[x]++;
		if(m<q[x]) m=q[x];
	}
	cout<<m<<endl;
}

D - Almost Difference

Let’s denote a function
d ( x , y ) = { y − x , if  ∣ x − y ∣ > 1 0 , if  ∣ x − y ∣ ≤ 1 d(x,y) = \begin{cases}y-x, &\text{if } |x-y|>1\\0, &\text{if } |x-y|≤1\end{cases} d(x,y)={yx,0,if xy>1if xy1
You are given an array a consisting of n integers. You have to calculate the sum of d(a i, a j) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
从第二个位子开始判断,例如第i个位子数字为x,则在之前的x,x-1,x+1,均无效,所有的d(x,y),y=a[i],所以和为a[i]*有效位数-之前位子除(x,x-1,x+1)以外的和。用map记录之前数字出现次数,b数组存之前的和。(除此之外,就是数据过大,要开long double);
备注long double 会自动科学计数。

#include<bits/stdc++.h>
using namespace std;
long double a[2000002],b[2000002];
map<long long,long long>mp;
int main(){
	int n;
	cin>>n;
	long double sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=b[i-1]+a[i];
		mp[a[i]]++;
		long double x=a[i]-1;int y=a[i]; int z=a[i]+1;
		if(i!=1)
		sum=sum+y*(i-mp[x]-mp[y]-mp[z])-(b[i-1]-x*mp[x]-y*(mp[y]-1)-z*mp[z]);
	}
	cout<<fixed<<setprecision(0)<<sum<<endl;
}

E - Swapping Characters

题目:We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s 1, s 2, …, s k. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string).

You are given k strings s 1, s 2, …, s k, and you have to restore any string s so that it is possible to obtain these strings by performing aforementioned operations. Note that the total length of the strings you are given doesn’t exceed 5000 (that is, k·n ≤ 5000).
大意
就是每个字符串进行一次操作:互换两个字符位子,令所有字符串相同
nnk的复杂度并不会超时,所以这题就是暴力枚举
难点
如果字符串内无重复字符,可能出现字符串达成相同,但无法交换位子,导致出错。

#include<bits/stdc++.h>
using namespace std;
int n, m, dist[2505];
char s[2505][5005];
map< char, int > mp[2505];
bool t;
int main()
{
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++) scanf("%s", s[i]+1);
    for(int j=1;j<=m;j++) 
	{
        mp[1][s[1][j]]++;
        if(mp[1][s[1][j]]>1) t=true;
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=m;j++) 
		{
           mp[i][s[i][j]]++;
           if(s[i][j]!=s[1][j]) dist[i]++;
        }
        if(mp[i]!=mp[1]) 
		{	cout<<-1<<endl; return 0;}
    }
    for(int l=1;l<=m;l++)
    for(int r=l+1;r<=m;r++)
    {
        bool flag=true;
        for(int i=2;i<=n;i++)
        {
            int tmp=dist[i];
            //先把假设要交换的两位的相关情况去除(dist存的是第i个字符串和第一个字符串有几个不同)
            if(s[i][l]!=s[1][l]) tmp--;
            if(s[i][l]!=s[1][r]) tmp++;
            if(s[i][r]!=s[1][r]) tmp--;
            if(s[i][r]!=s[1][l]) tmp++;
            if( !((tmp==2)||(tmp==0&&t))) 
			{
                flag=false; break;
            }
        }
        if(flag) {
            swap(s[1][l], s[1][r]);
            printf("%s\n", s[1]+1);
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值