2020济南站

链接:https://ac.nowcoder.com/acm/contest/11407/C
来源:牛客网

题目描述
MianKing has nn piles of stones and each pile has at most 33 stones, now he wants to merge all of these stones into one pile.

In order to achieve his goal, each time MianKing can choose two piles of stones and merge them into a new pile, and the number of stones in the new pile is the sum of these two piles.

Because it takes manpower to move stones, in each operation if the numbers of these two piles of stones are xx and yy respectively, MianKing should pay (xmod3)(ymod3)(x mod 3)(y mod 3) coins for it.

Now MianKing wants to know the minimum amount of coins he need to pay to merge all of these stones into one pile.

输入描述:
The first line has 33 integers a_1,a_2,a_3a
1

,a
2

,a
3

. And a_ia
i

denotes the number of piles which have ii stones.

0\leq a_i\leq 10^90≤a
i

≤10
9

\sum_{i=1}^{3}a_i>0∑
i=1
3

a
i

0
输出描述:
Output one integer: the minimum amount of coins MianKing need to pay for his goal.
示例1
输入
复制
1 1 1
输出
复制
2
示例2
输入
复制
99 66 55
输出
复制
165

题目大意:有一个石头的石头堆,有两个石头的石头堆,有三个石头的石头堆,每两堆石头合并的代价是分别对3取余数然后的乘积,问合并成一堆的代价最少是多少

思路:3的倍数的石头堆合并不花代价,如果让3的倍数的石头和1的倍数的石头合并的话,还会产生1的倍数的石头堆,所以并没有意义,如果是1和1合并的话花费是1,2和2合并的花费是4,1和2的合并花费是2,因为2和2合并的花费太高了,所以尽量让1和2的石头合并,剩下的再各自合并各自的

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

inline int read(int out = 0)
{
    
    
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 2e4 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int PP = 131;

signed main(){
    
    
	int a, b, c;
	gt(a), gt(b), gt(c);
	int ans = 0;
	ans = (min(a, b) * 2 );
	if (a > b){
    
    
		ans += (a - b) / 3 * 3;
		if ((a - b) % 3 == 2)   ans += 1;
	}
	if (b > a){
    
    
		ans += (b - a) / 3 * 6;
		if ((b - a) % 3 == 2)   ans += 4;
	}
	
	cout << ans << endl;
	
	return 0;
}

Fight against involution
链接:https://ac.nowcoder.com/acm/contest/10662/D
来源:牛客网

题目描述
MianKing chose a course in this semester. There are nn students in this course, and everyone needs to write a final paper. Let w_iw
i

denote the word count of the i-th student’s final paper.

The i-th student has a lower bound L_iL
i

and an upper bound R_iR
i

on the number of words in his final paper so that L_i\leq w_i\leq R_iL
i

≤w
i

≤R
i

The grade rule of this course is very amazing. The grade of the i-th student g_ig
i

is n-K_in−K
i

, K_iK
i

is the number of j \in [1,n]j∈[1,n] satisfies that w_j>w_iw
j

w
i

.

Every student wants to achieve the highest possible grade, so under the optimal decision w_iw
i

will equal to R_iR
i

for the i-th student.

But MianKing found an interesting thing: let’s assume that \forall i \in [1,n], L_i=1000,R_i=10000∀i∈[1,n],L
i

=1000,R
i

=10000. Under the optimal decision w_iw
i

are all equal to 1000010000 and the grades of the students are all nn. But if everyone only writes 1000 words in their final papers, their grades are still all nn and they can use the time they save to play games.

Now to fight against involution, MianKing wants to decide w_iw
i

for each student, and his plan has to satisfy the following conditions:

For each student, his grade cannot be less than that in the original plan.

Minimize the sum of w_iw
i

.

You need help MianKing calculate the minimum value of \sum_{i=1}^{n}w_i∑
i=1
n

w
i

输入描述:
The first line has one integer nn.

Then there are nn lines, the i-th line has two integers L_i,R_iL
i

,R
i

.

1\leq n\leq 10^51≤n≤10
5

1\leq L_i\leq R_i\leq 10^91≤L
i

≤R
i

≤10
9

输出描述:
Output the minimum value of \sum_{i=1}^{n}w_i∑
i=1
n

w
i

.
示例1
输入
复制
3
1 10000
1 10000
1 10000
输出
复制
3
示例2
输入
复制
4
1 2
2 2
2 4
3 4
输出
复制
10

题目大意:每个人最低写l个单词,最多写r个单词,每个人的分数是比他单词小于等于的人数,所以一开始每个人都写r个单词,但是现在要求他们的分数不会变的更低,但是要求每个人写的单词是一样多的,问最多可以写多少个单词

思路:可以先按照每个人的r从小到大排序,原来的时候,r一样的两个人的分数一定是相等的,现在让他们还想等,并且他们的单词是最少的,只需要让每个人写这堆人的l的最大值即可,并且这个最大值一定要大于等于上一堆人写的单词数量,不然的话这堆人的分数就有可能减少,把每队人写的单词数量和加起来即可

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <ext/rope>
#include <bits/stdc++.h> 

using namespace std;

#define gt(x) x = read()
#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

const int mod = 1e9 + 7;
const int PP = 131;

inline int read(int out = 0)
{
    
    
    char c;
    while((c=getchar()) < 48 || c > 57);
    while(c >= 48 && c <= 57) out=out*10+c-48,c=getchar();
    return out; 
}

const int N = 1e5 + 10;
const int M = 1e6 + 10;

struct Node{
    
    
	int l, r;
	bool operator<(const Node &W)const{
    
    
		return r < W.r;
	}
}node[N];

signed main(){
    
    
	int n;
	gt(n);
	for (int i = 1; i <= n; i ++){
    
    
		scanf("%lld%lld", &node[i].l, &node[i].r);
	}
	
	sort(node + 1, node + 1 + n);
	
	int pre = 1;
	int ans = 0;
	int pre1 = 0;
	for (int i = 1; i <= n;){
    
    
		int cnt = 0;
		while(i <= n && node[i].r == node[pre].r){
    
    
			i ++;
			cnt ++;
		}
		int res = 0;
		for (int j = pre; j <= (i - 1); j ++){
    
    
			res = max(res, node[j].l);
		}
		res = max(res, pre1);
		ans += res * (i - pre);
		pre = i;
		pre1 = res;
	}
	
	cout << ans << endl;
	return 0;
}

Xor Transformation
链接:https://ac.nowcoder.com/acm/contest/11407/G
来源:牛客网

MianKing has one integer XX, he wants to perform some operations to transform XX to YY (Y<X)(Y<X).

In each operation, MianKing can choose one integer 0\leq A<X0≤A<X and let X=XxorAX=X xor A.

It’s noticed that after an operation, the upper bound of AA will change because XX has changed.

Now you need to help MianKing to find a way to transform XX to YY by doing at most 55 operations.
输入描述:
The first line has two integers X,YX,Y.

1\leq Y<X\leq 10^{18}1≤Y<X≤10
18
.
输出描述:
The first line has one integer dd denotes the number of operations you did.

Then there are dd integers A_{1…d}A
1…d

denotes the AA you choose in each operations.

0\leq d\leq 50≤d≤5.
示例1
输入
复制
5 3
输出
复制
3
1 2 5

题目大意:
给你

猜你喜欢

转载自blog.csdn.net/qq_45772483/article/details/112702709