Codeforces Round 883 (Div. 3)

目录

A. Rudolph and Cut the Rope

B. Rudolph and Tic-Tac-Toe

C. Rudolf and the Another Competition

D. Rudolph and Christmas Tree

E1. Rudolf and Snowflakes (simple version)

E2. Rudolf and Snowflakes (hard version)


A. Rudolph and Cut the Rope

                                                time limit per test2 seconds
                                        memory limit per test256 megabytes
                                                        inputstandard input
                                outputstandard output
There are nn nails driven into the wall, the ii-th nail is driven aiai meters above the ground, one end of the bibi meters long rope is tied to it. All nails hang at different heights one above the other. One candy is tied to all ropes at once. Candy is tied to end of a rope that is not tied to a nail.

To take the candy, you need to lower it to the ground. To do this, Rudolph can cut some ropes, one at a time. Help Rudolph find the minimum number of ropes that must be cut to get the candy.

The figure shows an example of the first test:

Input
The first line contains one integer t (1\leq t\leq 10^{4}) — the number of test cases.

The first line of each test case contains one integer n (1\leq n\leq 50) — the number of nails.

The ii-th of the next nn lines contains two integers aiai and bibi (1\leq a_{i},b_{i}\leq 200) — the height of the ii-th nail and the length of the rope tied to it, all aiai are different.

It is guaranteed that the data is not contradictory, it is possible to build a configuration described in the statement.

Output
For each test case print one integer — the minimum number of ropes that need to be cut to make the candy fall to the ground.

input

4
3
4 3
3 1
1 2
4
9 2
5 2
7 7
3 4
5
11 7
5 10
12 9
3 2
1 5
3
5 6
4 5
7 7

output

2
2
3
0

#include<bits/stdc++.h>
using namespace std;
const int N=55;
int t,n,a[N],b[N];
void solve()
{
	int cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i]>>b[i];
		if(a[i]>b[i]) cnt++;
	}
	cout<<cnt<<endl;
}

signed main()
{
	cin>>t;
	while(t--) solve();
	return 0;
}

B. Rudolph and Tic-Tac-Toe

                                                        time limit per test1 second
                                                memory limit per test256 megabytes
                                                                inputstandard input
                                                              outputstandard output
Rudolph invented the game of tic-tac-toe for three players. It has classic rules, except for the third player who plays with pluses. Rudolf has a 3×33×3 field  — the result of the completed game. Each field cell contains either a cross, or a nought, or a plus sign, or nothing. The game is won by the player who makes a horizontal, vertical or diagonal row of 33's of their symbols.

Rudolph wants to find the result of the game. Either exactly one of the three players won or it ended in a draw. It is guaranteed that multiple players cannot win at the same time.

Input
The first line contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases.

Each test case consists of three lines, each of which consists of three characters. The symbol can be one of four: "X" means a cross, "O" means a nought, "+" means a plus, "." means an empty cell.

Output
For each test case, print the string "X" if the crosses won, "O" if the noughts won, "+" if the pluses won, "DRAW" if there was a draw.

input

5
+X+
OXO
OX.
O+.
+OX
X+O
.XO
OX.
+++
O.+
X.O
+..
.++
X.O
+..

output

X
O
+
DRAW
DRAW

枚举+判断

#include<bits/stdc++.h>
using namespace std;
const int N=5;
int t;
int n;
char g[N][N];

bool check(char x) 
{
	//横向 
	if(g[1][1]==g[1][2]&&g[1][2]==g[1][3]&&g[1][3]==x) return true;
	if(g[2][1]==g[2][2]&&g[2][2]==g[2][3]&&g[2][3]==x) return true;
	if(g[3][1]==g[3][2]&&g[3][2]==g[3][3]&&g[3][3]==x) return true;
	
	//纵向 
	if(g[1][1]==g[2][1]&&g[2][1]==g[3][1]&&g[3][1]==x) return true;
	if(g[1][2]==g[2][2]&&g[2][2]==g[3][2]&&g[3][2]==x) return true;
	if(g[1][3]==g[2][3]&&g[2][3]==g[3][3]&&g[3][3]==x) return true;
	
	//对角 
	if(g[1][1]==g[2][2]&&g[2][2]==g[3][3]&&g[3][3]==x) return true;
	if(g[3][1]==g[2][2]&&g[2][2]==g[1][3]&&g[1][3]==x) return true;
	return false;
}

void solve()
{
	n=3;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>g[i][j];
	bool f1=check('X');
	bool f2=check('O');
	bool f3=check('+');
	if(f1) puts("X");
	if(f2) puts("O");
	if(f3) puts("+");
	if(!f1&&!f2&&!f3) puts("DRAW");
}

signed main()
{
	cin>>t;
	while(t--) solve();
	return 0;
}

C. Rudolf and the Another Competition

                                                        time limit per test1 second
                                                memory limit per test256 megabytes
                                                                inputstandard input
                                                                outputstandard output
Rudolf has registered for a programming competition that will follow the rules of ICPC. The rules imply that for each solved problem, a participant gets 1 point, and also incurs a penalty equal to the number of minutes passed from the beginning of the competition to the moment of solving the problem. In the final table, the participant with the most points is ranked higher, and in case of a tie in points, the participant with the lower penalty is ranked higher.

In total, nn participants have registered for the competition. Rudolf is a participant with index 1. It is known that mm problems will be proposed. And the competition will last hh minutes.

A powerful artificial intelligence has predicted the values ti,jti,j, which represent the number of minutes it will take for the ii-th participant to solve the jj-th problem.

Rudolf realized that the order of solving problems will affect the final result. For example, if h=120, and the times to solve problems are [20,15,110], then if Rudolf solves the problems in the order:

3,1,2, then he will only solve the third problem and get 1 point and 110 penalty.
1,2,3, then he will solve the first problem after 20 minutes from the start, the second one after 20+15=35 minutes, and he will not have time to solve the third one. Thus, he will get 2 points and 20+35=55 penalty.
2,1,3, then he will solve the second problem after 15 minutes from the start, the first one after 15+20=35 minutes, and he will not have time to solve the third one. Thus, he will get 2 points and 15+35=50 penalty.
Rudolf became interested in what place he will take in the competition if each participant solves problems in the optimal order based on the predictions of the artificial intelligence. It will be assumed that in case of a tie in points and penalty, Rudolf will take the best place.

Input
The first line contains an integer tt (1\leq t\leq 10^{3}) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each test case contains three integers n,m,h (1\leq n\cdot m\leq 2\cdot 10^{5},1\leq h\leq 10^{6}) — the number of participants, the number of problems, and the duration of the competition, respectively.

Then there are nn lines, each containing mm integers ti,jti,j (1\leq t_{i,j}\leq 10^{6}) — the number of minutes it will take for the ii-th participant to solve the jj-th problem.

The sum of n⋅mn⋅m over all test cases does not exceed 2\cdot 10^{5}.

Output
For each test case, output an integer — Rudolf's place in the final table if all participants solve problems in the optimal order.

input

5
3 3 120
20 15 110
90 90 100
40 40 40
2 1 120
30
30
1 3 120
10 20 30
3 2 27
8 9
10 7
10 8
3 3 15
7 2 6
7 5 4
1 9 8

output

2
1
1
2
1

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n,m,h;

struct node
{
	int s,p,idx;
};

bool cmp(node &x,node &y)
{
	if(x.s==y.s) return x.p<y.p;
	return x.s>y.s;
}

void solve()
{
	cin>>n>>m>>h;
	int a[n+10][m+10]={0};
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	node p[n+10];
	for(int i=1;i<=n;i++)
	{
		sort(a[i]+1,a[i]+1+m);
		int time=h,cnt=0,pen=0,spen=0;
		for(int j=1;j<=m;j++)
			if(a[i][j]<=time)
			{
				cnt++;
				time-=a[i][j];
				pen+=a[i][j];
				spen+=pen;
			}
			else break;
		p[i].s=cnt;
		p[i].p=spen;
		p[i].idx=i;
	}
	int rank=1;
	for(int i=2;i<=n;i++)
		if(p[i].s>p[1].s||(p[i].s==p[1].s&&p[i].p<p[1].p))
			rank++;
	cout<<rank<<endl;
}

signed main()
{
	cin>>t;
	while(t--) solve();
	return 0;
}

Note
In the first example, Rudolf will get 2 points and 50 penalty minutes. The second participant will solve only one problem and get 1 point and 90 penalty minutes. And the third participant will solve all 3 problems and get 3 points and 240 penalty minutes. Thus, Rudolf will take the second place.

In the second example, both participants will get 1 point and 30 penalty minutes. In case of a tie in points, Rudolf gets the better position, so he will take the first place.

In the third example, Rudolf is the only participant, so he will take the first place.

In the fourth example, all participants can solve two problems with penalty of 25=8+(8+9), 24=7+(7+10) and 26=8+(8+10), respectively, thanks to the penalty, the second participant gets the first place, and Rudolf gets the second.

D. Rudolph and Christmas Tree

                                                       time limit per test2 seconds
                                                memory limit per test256 megabytes
                                                             inputstandard input
                                                           outputstandard output
Rudolph drew a beautiful Christmas tree and decided to print the picture. However, the ink in the cartridge often runs out at the most inconvenient moment. Therefore, Rudolph wants to calculate in advance how much green ink he will need.

The tree is a vertical trunk with identical triangular branches at different heights. The thickness of the trunk is negligible.

Each branch is an isosceles triangle with base dd and height hh, whose base is perpendicular to the trunk. The triangles are arranged upward at an angle, and the trunk passes exactly in the middle. The base of the ii-th triangle is located at a height of yi.

The figure below shows an example of a tree with d=4,h=2 and three branches with bases at heights [1,4,5].

Help Rudolph calculate the total area of the tree branches.

Input
The first line contains a single integer tt (1\leq t\leq 10^{4}) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each test case contains three integers n,d,h (1\leq n,d,h\leq 2\cdot 10^{5}) — the number of branches, the length of the base, and the height of the branches, respectively.

The second line of each test case contains nn integers yiyi (1\leq y_{i}\leq 10^{9},y_{1}<y_{2}<......<y_{n}) — the heights of the bases of the branches.

The sum of nn over all test cases does not exceed 2\cdot 10^{5}.

Output
For each test case, output a single real number on a separate line — the total area of the tree branches. The answer will be considered correct if its absolute or relative error does not exceed 10^{6}.

Example

 input

5
3 4 2
1 4 5
1 5 1
3
4 6 6
1 2 3 4
2 1 200000
1 200000
2 4 3
9 11

output

11
2.5
34.5
199999.9999975
11.333333

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int t,n;
double d,h;
double y[N];

void solve()
{
	cin>>n>>d>>h;
	for(int i=1;i<=n;i++) cin>>y[i];
	sort(y+1,y+n+1);
	double ans=n*d*h/2;
	double res=0;
	for(int i=1;i<n;i++)
	{
		if(y[i]+h>y[i+1]) 
		{
			double x=(double)(y[i]+h-y[i+1])*(y[i]+h-y[i+1])*d/(2*h); 
			res+=x;
		}
	}
	printf("%.10lf\n",ans-res);
}

signed main()
{
	cin>>t;
	while(t--) solve();
	return 0;
}

E1. Rudolf and Snowflakes (simple version)

                                                time limit per test2 seconds
                                        memory limit per test256 megabytes
                                                        inputstandard input
                                                        outputstandard output
This is a simple version of the problem. The only difference is that in this version n≤106n≤106.

One winter morning, Rudolf was looking thoughtfully out the window, watching the falling snowflakes. He quickly noticed a certain symmetry in the configuration of the snowflakes. And like a true mathematician, Rudolf came up with a mathematical model of a snowflake.

He defined a snowflake as an undirected graph constructed according to the following rules:

Initially, the graph has only one vertex.
Then, more vertices are added to the graph. The initial vertex is connected by edges to kk new vertices (k>1).
Each vertex that is connected to only one other vertex is connected by edges to kk more new vertices. This step should be done at least once.
The smallest possible snowflake for k=4 is shown in the figure.

After some mathematical research, Rudolf realized that such snowflakes may not have any number of vertices. Help Rudolf check if a snowflake with nn vertices can exist.

Input
The first line of the input contains an integer tt (1\leq t\leq 10^{4}) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each test case contains an integer nn (1\leq n\leq 10^{6}) — the number of vertices for which it is necessary to check the existence of a snowflake.

Output
Output tt lines, each of which is the answer to the corresponding test case — "YES" if there exists such k>1 for which a snowflake with the given number of vertices can be constructed; "NO" otherwise.

input

9
1
2
3
6
13
15
255
10101
1000000

output

NO
NO
NO
NO
YES
YES
YES
YES
NO

本题的意思可以拆分为n是否可以拆成n=k^0+k^1+k^2...

都是满足右边的式子至少是2项,直接包搜k.

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,n;

void solve()
{
	cin>>n;
	bool flag=false;
	for(int k=2;k<=1000;k++)
	{
		int x=n,cnt=0;;
		for(int i=0;x>0;i++) 
		{
			cnt++;
			x-=pow(k,i);
		}
		if(x==0&&cnt>=3) 
		{
			flag=true;
			break;
		}
	}
	//if(n==1||n==2||n==3||n==6) flag=false;
	if(flag) 
	{
		puts("YES");
	}
	else puts("NO");
}

signed main()
{
	cin>>t;
	while(t--) solve();
	return 0;
}

E2. Rudolf and Snowflakes (hard version)

                                                time limit per test2 seconds
                                        memory limit per test256 megabytes
                                                        inputstandard input
                                                        outputstandard output

This is the hard version of the problem. The only difference is that in this version n\leq 10^{18}.

One winter morning, Rudolf was looking thoughtfully out the window, watching the falling snowflakes. He quickly noticed a certain symmetry in the configuration of the snowflakes. And like a true mathematician, Rudolf came up with a mathematical model of a snowflake.

He defined a snowflake as an undirected graph constructed according to the following rules:

Initially, the graph has only one vertex.
Then, more vertices are added to the graph. The initial vertex is connected by edges to kk new vertices (k>1).
Each vertex that is connected to only one other vertex is connected by edges to kk more new vertices. This step should be done at least once.
The smallest possible snowflake for k=4 is shown in the figure.

After some mathematical research, Rudolf realized that such snowflakes may not have any number of vertices. Help Rudolf check if a snowflake with nn vertices can exist.

Input
The first line of the input contains an integer tt (1\leq t\leq 10^{4}) — the number of test cases.

Then follow the descriptions of the test cases.

The first line of each test case contains an integer nn (1\leq n\leq 10^{6}) — the number of vertices for which it is necessary to check the existence of a snowflake.

Output
Output tt lines, each of which is the answer to the corresponding test case — "YES" if there exists such k>1 for which a snowflake with the given number of vertices can be constructed; "NO" otherwise.

input

9
1
2
3
6
13
15
255
10101
1000000000000000000

output

NO
NO
NO
NO
YES
YES
YES
YES
NO

参考大佬的代码: 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <ctime>
#include <limits>
#include <climits>
#include <cfloat>
#include <strstream>
#include <sstream>
#include <fstream>
#include <random>
#include <numeric>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned int U32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<string, string> PSS;
typedef pair<string, int> PSI;
typedef pair<int, string> PIS;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef map<int, string> MIS;
typedef map<string, string> MSS;
typedef map<int, vector<int>> MIVI;
typedef set<int> SI;


const LL INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const LL MOD = 1e9 + 7;
const LD PI = acos(-1);

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define ms(a, x) memset(a, x, sizeof a)
//---------------------------------------------------------------------------------


void solve() {
    LL n, flg = 0;
    cin >> n;
    int cnt = 1;
    while (true){
        cnt++;
        LL p = pow(n, 1.0 / cnt);
        LL a = 1, s = 1;
        for (int i = 1; i <= cnt; i++){
            a *= p;
            s += a;
        }
        if (p == 1) {
            break;
        } if (s == n) {
            flg = 1;
            break;
        }
    }
    if (flg == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    IOS;
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值