GVKun编程网logo

Codeforces Round #576 (Div. 2) B - Water Lily

23

本文的目的是介绍CodeforcesRound#576(Div.2)B-WaterLily的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于CodeforceRound57

本文的目的是介绍Codeforces Round #576 (Div. 2) B - Water Lily的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于Codeforce Round 578 Div. 2 A. Hotelier、Codeforces Round #257 (Div. 2)、Codeforces Round #257 (Div. 2) 题解、Codeforces Round #557 (Div. 2)的知识。

本文目录一览:

Codeforces Round #576 (Div. 2) B - Water Lily

Codeforces Round #576 (Div. 2) B - Water Lily

Codeforces Round #576 (Div. 2)

 

B - Water Lily

While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake''s surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surface.

 

 

Suppose that the lily grows at some point A on the lake bottom, and its stem is always a straight segment with one endpoint at point A. Also suppose that initially the flower was exactly above the point A, i.e. its stem was vertical. Can you determine the depth of the lake at point A?

Input

The only line contains two integers H and L (1≤H<L≤10^6).

Output

Print a single number — the depth of the lake at point A. The absolute or relative error should not exceed 10^−6.

Formally, let your answer be A, and the jury''s answer be B. Your answer is accepted if and only if |A−B|max(1,|B|)≤10^−6.

Examples

input

1 2

output

1.5000000000000

input

3 5

output

2.6666666666667

 

思路:几何数学题,看图我们可以列出方程  ,

化简之后得  ,由此得解

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<map>
 6 #include<set>
 7 #include<vector>
 8 #include<algorithm>
 9 #include<queue>
10 #include<unordered_map>
11 #include<list>
12 using namespace std;
13 #define ll long long 
14 const int mod=1e9+7;
15 const int inf=1e9+7;
16  
17 const int maxn=1e5+5;
18  
19 int main()
20 {
21     //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
22     
23     double H,L;
24     
25     while(cin>>H>>L)
26     {
27         double x=(L*L-H*H)/(2*H);
28         printf("%.10f\n",x);
29     }
30     
31     return 0;
32 }

 

Codeforce Round 578 Div. 2 A. Hotelier

Codeforce Round 578 Div. 2 A. Hotelier

A. Hotelier

Problem

Amugae has a hotel consisting of $10$ rooms. The rooms are numbered from $0$ to $9$ from left to right.

The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entrance, they are assigned to an empty room closest to the left entrance. Similarly, when a customer arrives at the hotel through the right entrance, they are assigned to an empty room closest to the right entrance.

One day, Amugae lost the room assignment list. Thankfully Amugae''s memory is perfect, and he remembers all of the customers: when a customer arrived, from which entrance, and when they left the hotel. Initially the hotel was empty. Write a program that recovers the room assignment list from Amugae''s memory.

Input

The first line consists of an integer $n (1 \leq n \leq 105)$, the number of events in Amugae''s memory.

The second line consists of a string of length $n$ describing the events in chronological order. Each character represents:

''L'': A customer arrives from the left entrance. ''R'': A customer arrives from the right entrance. ''0'', ''1'', ..., ''9'': The customer in room x (0, 1, ..., 9 respectively) leaves.

It is guaranteed that there is at least one empty room when a customer arrives, and there is a customer in the room $x$ when $x (0, 1, ..., 9)$is given. Also, all the rooms are initially empty.

Output

In the only line, output the hotel room''s assignment status, from room $0$ to room $9$. Represent an empty room as ''0'', and an occupied room as ''1'', without spaces.

Examples

input

8 LLRL1RL1

output

1010000011

input

9 L0L0LLRR9

output

1100000010

Note

In the first example, hotel room''s assignment status after each action is as follows.

·First of all, all rooms are empty. Assignment status is 0000000000. ·L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. ·L: one more customer from the left entrance. Assignment status is 1100000000. ·R: one more customer from the right entrance. Assignment status is 1100000001. ·L: one more customer from the left entrance. Assignment status is 1110000001. ·1: the customer in room 1 leaves. Assignment status is 1010000001. ·R: one more customer from the right entrance. Assignment status is 1010000011. ·L: one more customer from the left entrance. Assignment status is 1110000011. ·1: the customer in room 1 leaves. Assignment status is 1010000011.

So after all, hotel room''s final assignment status is 1010000011.

In the second example, hotel room''s assignment status after each action is as follows.

·L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. ·0: the customer in room 0 leaves. Assignment status is 0000000000. ·L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000 again. ·0: the customer in room 0 leaves. Assignment status is 0000000000. ·L: a customer arrives to the hotel through the left entrance. Assignment status is 1000000000. ·L: one more customer from the left entrance. Assignment status is 1100000000. ·R: one more customer from the right entrance. Assignment status is 1100000001. ·R: one more customer from the right entrance. Assignment status is 1100000011. ·9: the customer in room 9 leaves. Assignment status is 1100000010.

So after all, hotel room''s final assignment status is 1100000010.

想法

暴力出奇迹

The Code Of My Program

/*********************
*@Author:   ChenShou *
*@Language: C++11    *
*********************/
//#include <bits/stdc++.h> 
#pragma comment(linker, "/STACK:102400000,102400000")
#include<functional>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
 
//#define DEBUG
#define RI register int
#define endl "\n"
 
using namespace std;
typedef long long ll;
//typedef __int128 lll;
//const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-9;
const int INF = 0x3f3f3f3f;
 
inline ll read(){
    long long x=0,f=1;
    char ch=getchar();
    while(ch<''0''||ch>''9''){
        if(ch==''-'')
            f=-1;
        ch=getchar();
    }
    while(ch>=''0''&&ch<=''9''){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f; 
}
 
int n;
 
int room [15]={0};
 
char op[100005];
 
int main()
{
#ifdef DEBUG
    freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif
    //cout.tie(0);
    //scanf("%d",&t);
    //while(t--){
    //}
    n=read();
    scanf("%s",op);
    for(int i=0;i<n;i++){
    	if(op[i]==''L''){
    		for(int j=0;j<=9;j++){
    			if(!room[j]){
    				room[j]=1;
    				break;
    			}
    		}
    	}else 
		if(op[i]==''R''){
    		for(int j=9;j>=0;j--){
    			if(!room[j]){
    				room[j]=1;
    				break;
    			}
    		}
    	}
    	else {
    		int now=op[i]-''0'';
    			room[now]=0;
    	}
    }
    for(int i=0;i<10;i++){
    	printf("%d",room[i]);
    }
#ifdef DEBUG
    printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Fuck You !" << endl;
    return 0;
}

Codeforces Round #257 (Div. 2)

Codeforces Round #257 (Div. 2)

Codeforces Round #257 (Div. 2)

https://codeforces.com/contest/450/

A

模拟

分享图片

分享图片

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,mid,rt<<1
 4 #define rson mid+1,r,rt<<1|1
 5 #define sqr(x) ((x)*(x))
 6 #define pb push_back
 7 #define eb emplace_back
 8 #define maxn 100005
 9 #define eps 1e-8
10 #define pi acos(-1.0)
11 #define rep(k,i,j) for(int k=i;k<j;k++)
12 typedef long long ll;
13 typedef pair<int,int> pii;
14 typedef pair<long long,int>pli;
15 typedef pair<int,char> pic;
16 typedef pair<pair<int,string>,pii> ppp;
17 typedef unsigned long long ull;
18 const long long MOD=1e9+7;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt","r",stdin);
21 #endif */
22 
23 int n,m;
24 int a[105];
25 
26 int main(){
27     #ifndef ONLINE_JUDGE
28      //   freopen("1.txt",stdin);
29     #endif
30     cin>>n>>m;
31     for(int i=0;i<n;i++){
32         cin>>a[i];
33     }
34     int pos=0;
35     int i=0;
36     int co=0;
37     while(1){
38         if(a[i]>0){
39             pos=i;
40             a[i]-=min(m,a[i]);
41             co=0;
42         }
43         else {
44             co++;
45         }
46         i=(i+1)%n;
47         if(co==n) break;
48     }
49     cout<<pos+1<<endl;
50 
51 }
View Code

 

B

矩阵快速幂

分享图片

分享图片

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,pii> ppp;
17 typedef unsigned long long ull;
18 const long long mod=1e9+7;
19 /*#ifndef ONLINE_JUDGE
20         freopen("1.txt",stdin);
21 #endif */
22 ll n,m,k;
23 struct sair{
24     ll a[3][3];
25     sair(){
26         a[0][0]=0,a[0][1]=0;
27         a[1][0]=0,a[1][1]=0;
28     }
29     friend sair operator*(const sair&a,const sair &b){
30         sair ans;
31         for(int i=0;i<2;i++){
32             for(int j=0;j<2;j++){
33                 for(int k=0;k<2;k++){
34                     ans.a[i][j]=(ans.a[i][j]+a.a[i][k]*b.a[k][j]%mod+mod)%mod;
35                 }
36             }
37         }
38         return ans;
39     }
40 };
41 
42 sair pow_mul(sair a){
43     k-=2;
44     sair base;
45     base.a[0][0]=1,base.a[0][1]=0;
46     base.a[1][0]=0,base.a[1][1]=1;
47     while(k){
48         if(k&1)
49             base=base*a;
50         k>>=1;
51         a=a*a;
52     }
53     return base;
54 }
55 
56 int main(){
57     #ifndef ONLINE_JUDGE
58      //   freopen("1.txt",stdin);
59     #endif
60     cin>>n>>m>>k;
61     sair a;
62     a.a[0][0]=(m+mod)%mod,a.a[0][1]=0;
63     a.a[1][0]=(n+mod)%mod,a.a[1][1]=0;
64     if(k==1) cout<<a.a[1][0]<<endl;
65     else if(k==2) cout<<a.a[0][0]<<endl;
66     else {
67         sair base;
68         base.a[0][0]=1,base.a[0][1]=-1;
69         base.a[1][0]=1,base.a[1][1]=0;
70         sair tmp=pow_mul(base);
71         base=tmP*a;
72         cout<<(base.a[0][0]+mod)%mod<<endl;
73     }
74 
75 }
View Code

 

C

找规律

分享图片

分享图片

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,stdin);
21 #endif */
22 
23 int main(){
24     #ifndef ONLINE_JUDGE
25      //   freopen("1.txt",stdin);
26     #endif
27     ll n,k;
28     cin>>n>>m>>k;
29     ll tmp=(n-1)+(m-1);
30     if(n-1==0) tmp=m-1;
31     if(m-1==0) tmp=n-1;
32     if(n-1==0&&m-1==0) tmp=0;
33     if(tmp<k) cout<<-1<<endl;
34     else{
35         ll ans=0;
36         if(k>=n)ans=max(ans,m/(k-n+2));
37         if(k>=m)ans=max(ans,n/(k-m+2));
38         if(k<n)ans=max(ans,m*(n/(k+1)));
39         if(k<m)ans=max(ans,n*(m/(k+1)));
40         cout<<ans<<endl;
41     }
42 
43 }
View Code

 

D

最短路水题 把要被松弛的边找出来即可

分享图片

分享图片

  1 #include<bits/stdc++.h>
  2 using namespace std;
  3 #define lson l,rt<<1
  4 #define rson mid+1,rt<<1|1
  5 #define sqr(x) ((x)*(x))
  6 #define pb push_back
  7 #define eb emplace_back
  8 #define maxn 100005
  9 #define eps 1e-8
 10 #define pi acos(-1.0)
 11 #define rep(k,j) for(int k=i;k<j;k++)
 12 typedef long long ll;
 13 typedef pair<int,int> pii;
 14 typedef pair<long long,int>pli;
 15 typedef pair<int,char> pic;
 16 typedef pair<pair<int,pii> ppp;
 17 typedef unsigned long long ull;
 18 const long long mod=1e9+7;
 19 /*#ifndef ONLINE_JUDGE
 20         freopen("1.txt",stdin);
 21 #endif */
 22 
 23 int n,k;
 24 vector<pli>ve[200005];
 25 ll dis[200005];
 26 bool book[200005];
 27 bool vis[200005];
 28 int ans;
 29 int co;
 30 void Dijstra(){
 31     priority_queue<pli,vector<pli>,greater<pli> >Q;
 32     dis[1]=0;
 33     int flag;
 34     Q.push({0,1});
 35     for(int i=0;i<=n;i++){
 36         if(book[i]==1){
 37             Q.push({dis[i],i});
 38         }
 39     }
 40     while(!Q.empty()){
 41         pli s=Q.top();
 42         Q.pop();
 43         int pos=s.second;
 44         if(!vis[pos]){
 45             vis[pos]=1;
 46             for(int i=0;i<ve[pos].size();i++){
 47                 flag=0;
 48                 int u=ve[pos][i].second;
 49                 ll len=ve[pos][i].first;
 50                 if(dis[u]>=dis[pos]+len){
 51                     if(dis[u]==dis[pos]+len){
 52                         flag=1;
 53                     }
 54                     dis[u]=dis[pos]+len;
 55                     if(book[u]){
 56                         ans++;
 57                         book[u]=0;
 58                     }
 59                     if(!flag) Q.push({dis[u],u});
 60                 }
 61             }
 62         }
 63     }
 64     for(int i=0;i<=n;i++){
 65         k-=book[i];
 66     }
 67     cout<<k<<endl;
 68 }
 69 
 70 int main(){
 71     #ifndef ONLINE_JUDGE
 72      //   freopen("1.txt",stdin);
 73     #endif
 74     cin>>n>>m>>k;
 75     int u,v;
 76     ll c;
 77     for(int i=0;i<=n;i++){
 78         dis[i]=0x3f3f3f3f3f3f3f3f;
 79         vis[i]=0;
 80         book[i]=0;
 81     }
 82     for(int i=1;i<=m;i++){
 83         cin>>u>>v>>c;
 84         ve[u].pb({c,v});
 85         ve[v].pb({c,u});
 86     }
 87     for(int i=1;i<=k;i++){
 88         cin>>u>>c;
 89         if(dis[u]>c){
 90             dis[u]=c;
 91             if(!book[u]){
 92                 book[u]=1;
 93             }
 94             else{
 95                 ans++;
 96             }
 97         }
 98         else{
 99             ans++;
100         }
101     }
102     Dijstra();
103     //cout<<ans<<endl;
104 
105 }
View Code

 

E

模拟题+数论

分享图片

分享图片

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define lson l,stdin);
21 #endif */
22 vector<int> a[maxn],ans;
23 bool book[maxn];
24 
25 int main(){
26     #ifndef ONLINE_JUDGE
27      //   freopen("1.txt",stdin);
28     #endif
29     int n;
30     cin>>n;
31     if(n==1){
32         cout<<0;
33         return 0;
34     }
35     for(int i=3;i<=n;i++){
36         if((i%2==1)&&book[i]==0 ){
37             for(int j=i;j<=n;j+=i){
38                 if(book[j]==0){
39                     a[i].push_back(j);
40                     book[j]=1;
41                 }
42 
43             }
44         }
45     }
46     for(int i=3;i<=(n/2);i++){
47         if(a[i].size()>0){
48             if(a[i].size()%2==1){
49                 a[i].erase(a[i].begin()+1);
50                 book[2*i]=0;
51             }
52             while(a[i].size()>0){
53                 ans.push_back(a[i].back());
54                 a[i].pop_back();
55             }
56         }
57     }
58     for(int i=2 ; i<=n ; i+=2){
59         if(book[i]==0){
60             a[2].push_back(i);
61         }
62     }
63     for(int i=0;i<a[2].size()-1;i+=2){
64         ans.push_back(a[2][i]);
65         ans.push_back(a[2][i+1]);
66     }
67     int answer=(ans.size()>>1);
68     cout<<answer<<endl;
69     for(int i=ans.size()-1;i>=0;i-=2){
70         cout<<ans[i]<<" "<<ans[i-1]<<endl;
71     }
72 }
View Code

Codeforces Round #257 (Div. 2) 题解

Codeforces Round #257 (Div. 2) 题解

Problem A A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n children in Jzzhu''s school. Jzzhu is going to give some candies to them. Let''s number

problem a

A. Jzzhu and Children

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n children in Jzzhu''s school. Jzzhu is going to give some candies to them. Let''s number all the children from 1 to n. The i-th child wants to get at least ai candies.

Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:

  1. Give m candies to the first child of the line.
  2. If this child still haven''t got enough candies, then the child goes to the end of the line, else the child go home.
  3. Repeat the first two steps while the line is not empty.

Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?

Input

The first line contains two integers n,?m (1?≤?n?≤?100; 1?≤?m?≤?100). The second line contains n integers a1,?a2,?...,?an (1?≤?ai?≤?100).

Output

Output a single integer, representing the number of the last child.

Sample test(s)

input

5 2
1 3 1 4 2
登录后复制

output

4
登录后复制

input

6 4
1 1 2 2 3 3
登录后复制

output

6
登录后复制

传送门:点击打开链接

解体思路:简单模拟题,用队列模拟这个过程即可。

代码:

#include <cstdio>
#include <queue>
using namespace std;

typedef pair<int int> P;
queue<p> q;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("257Ain.txt", "r", stdin);
	#endif
	int n, m, ans = 0;
	scanf("%d%d", &amp;n, &amp;m);
	for(int i = 0; i  m)
		{
			p.first -= m;
			q.push(p);
		}
		ans = p.second;
	}
	printf("%d\n", ans);
	return 0;
}
</p></int></queue></cstdio>
登录后复制


Problem B

B. Jzzhu and Sequences

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Jzzhu has invented a kind of sequences, they meet the following property:

Codeforces Round #257 (Div. 2) 题解

You are given x and y, please calculate fn modulo 1000000007 (109?+?7).

Input

The first line contains two integers x and y (|x|,?|y|?≤?109). The second line contains a single integer n (1?≤?n?≤?2·109).

Output

Output a single integer representing fn modulo 1000000007 (109?+?7).

Sample test(s)

input

2 3
3
登录后复制

output

1
登录后复制

input

0 -1
2
登录后复制

output

1000000006
登录后复制

传送门:点击打开链接

解体思路:简单数学公式的推导,

f(n) = f(n-1) + f(n+1), f(n+1) = f(n) + f(n+2);

两式相加得:f(n-1) + f(n+2) = 0,

由上式可推得:f(n+2) + f(n+5) = 0;

由上两式得:f(n-1) = f(n+5),所以f(n)的周期为6;

我们只需求出f的前六项即可,ps:注意一点,f(n)可能为负值,对负数取模要先对负数加mod,使负数变为正数之后再取模。

代码:

#include <cstdio>

const int mod = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE
	//freopen("257Bin.txt", "r", stdin);
	#endif
	int n, a [7];
	scanf("%d%d%d", &amp;a[0], &amp;a[1], &amp;n);
	for(int i = 2; i = 0 ? t % mod : (t + 2 * mod) % mod);
	return 0;
}
</cstdio>
登录后复制

Problem C

C. Jzzhu and Chocolate

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Jzzhu has a big rectangular chocolate bar that consists of n?×?m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:

The picture below shows a possible way to cut a 5?×?6 chocolate for 5 times.

Codeforces Round #257 (Div. 2) 题解

Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.

Input

A single line contains three integers n,?m,?k (1?≤?n,?m?≤?109; 1?≤?k?≤?2·109).

Output

Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.

Sample test(s)

input

3 4 1
登录后复制

output

6
登录后复制

input

6 4 2
登录后复制

output

8
登录后复制

input

2 3 4
登录后复制

output

-1
登录后复制
传送门:点击打开链接

解体思路:

n行m列,在水平方向最多切n-1刀,竖直方向最多切m-1刀,如果k>n+m-2,就是不能切割的情况;我们找出沿水平方向或竖直方向可以切的最多的刀数mx,如果k>mx,我们就现在这个方向切mx刀,剩下的就是要将一条长为(mn+1)巧克力切(k - mx)刀;其他的情况就是要么就是沿着水平方向切k刀,要么就是沿着竖直方向切k刀,取两者间的大者。

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n, m, k;
	long long ans = -1;
	cin &gt;&gt; n &gt;&gt; m &gt;&gt; k;
	if(k &gt; n + m -2)
		ans = -1;
	else
	{
		int mx = max(n - 1, m - 1);
		int mn = min(n - 1, m - 1);
		if(k &gt; mx)
			ans = (mn + 1) / (k - mx + 1);
		else
			ans = max(1ll * n / (k + 1) * m, 1ll * m / (k + 1) * n);
	}
	cout <br><br></algorithm></iostream></cstdio>
登录后复制

Codeforces Round #557 (Div. 2)

Codeforces Round #557 (Div. 2)

手速场。

题目链接:http://codeforces.com/contest/1201

A:

按题意模拟就完事了。

分享图片

分享图片

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 int n,m;
21 string s[1010];
22 int a[1010];
23 ll ans = 0;
24 
25 int main() {
26     cin >> n >> m;
27     for (int i = 1; i <= n; i++) cin >> s[i];
28     for (int i = 1; i <= m; i++) cin >> a[i];
29     for (int j = 0; j < m; j++) {
30         int maxx = 0; map<char,int>m;
31         for (int i = 1; i <= n; i++) maxx = max(maxx,++m[s[i][j]]);
32         ans += (ll)maxx * a[j + 1];
33     }
34     printf("%lld\n",ans);
35     return 0;
36 }
View Code

B:

检查所有元素的和是否为奇数,若为奇数则NO。

若最大元素大于和的一半,也为NO。

分享图片

分享图片

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 int x,n,maxx = 0;
21 ll sum = 0;
22 
23 int main() {
24     scanf("%d",&n);
25     rep1(i,1,n) {
26         int x; scanf("%d",&x);
27         maxx = max(maxx,x);
28         sum += x;
29     }
30     if (sum < maxx * 2 || sum & 1) puts("NO");
31     else puts("YES");
32     return 0;
33 }
View Code

C:

直接从n/2+1这个位置往后填就可以了。

分享图片

分享图片

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 const int maxn = 2e5 + 10;
21 ll n,k,a[maxn];
22 
23 int main() {
24     scanf("%lld%lld",&n,&k);
25     rep1(i,1,n) scanf("%lld",&a[i]);
26     sot(a,n);
27     int cnt = 1;
28     for (int i = n / 2 + 1; i < n; i++) {
29         if (k / cnt >= a[i + 1] - a[i]) {
30             k -= (a[i + 1] - a[i]) * cnt;
31             cnt++;
32         } else return printf("%lld\n",a[i] + k / cnt),0;
33     }
34     printf("%lld\n",a[n] + k / (n / 2 + 1));
35     return 0;
36 }
View Code

今天关于Codeforces Round #576 (Div. 2) B - Water Lily的分享就到这里,希望大家有所收获,若想了解更多关于Codeforce Round 578 Div. 2 A. Hotelier、Codeforces Round #257 (Div. 2)、Codeforces Round #257 (Div. 2) 题解、Codeforces Round #557 (Div. 2)等相关知识,可以在本站进行查询。

本文标签: