2020 Jinan Railway Station

Link: https://ac.nowcoder.com/acm/contest/11407/C
Source: Niuke

题目描述
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 description:
Output one integer: the minimum amount of coins MianKing need to pay for his goal.
Example 1
input
copy
1 1 1
output
copy
2
example 2
input
copy
99 66 55
output
copy
165

The main idea of ​​the topic: There is a pile of stones, a pile of two stones, and a pile of three stones. The cost of merging every two piles of stones is to take the remainder of 3 and then multiply the product. Ask the least cost of merging into one pile. How many

Idea: It doesn’t cost much to merge stone piles that are multiples of 3. If you merge stones that are multiples of 3 and stones that are multiples of 1, it will also produce stone piles that are multiples of 1, so it doesn’t make sense. If 1 and 1 are merged If the cost is 1, the combined cost of 2 and 2 is 4, the combined cost of 1 and 2 is 2, because the combined cost of 2 and 2 is too high, so try to merge the stones of 1 and 2, and then merge the rest. Respective

#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
link: https://ac.nowcoder.com/acm/contest/10662/D
Source: Niuke.com

题目描述
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

Input description:
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 Description:
the Output The Minimum value of \ sum_ {I} = ^ {n-1} w_iΣ
I = 1
n- W I . Example 1 Input Copy 3 1 10000 1 10000 1 10000 output copy 3 Example 2 Input Copy . 4 1 2 2 2 2 4 3 4 Output copy 10

























The main idea of ​​the topic: Everyone should write at least l words and at most r words. Each person's score is the number of people less than or equal to his word. So at the beginning everyone writes r words, but now they are required to keep their scores unchanged. Is lower, but requires everyone to write the same number of words, ask how many words can be written at most

Idea: You can sort each person's r from small to large first. In the past, the scores of two people with the same r must be equal. Now let them want to wait, and their words are the fewest, just let everyone Write the maximum value of l of this group of people, and this maximum value must be greater than or equal to the number of words written by the previous group of people, otherwise the scores of this group of people may be reduced, and the number of words written by each team Add it up

#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
link: https://ac.nowcoder.com/acm/contest/11407/G
Source: Niuke.com

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.
Example 1
input
copy
5 3
output
copy
3
1 2 5

Main idea: here
you are

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/112702709