题目链接
@[toc]

A - やめて嘘はあなたらしくないよ

The h-index of an author is the largest h where he has at least h papers with citations not less than h.
Bobo has published many papers.
Given a0,a1,a2,,an which means Bobo has published ai papers with citations exactly i, find the h-index of Bobo.
Input
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer n.
The second line contains (n+1) integers a0,a1,,an.
Output
For each test case, print an integer which denotes the result.
Constraint
1n2105
0ai109
The sum of n does not exceed 250,000.
Sample Input1
1 2
2
1 2 3
3
0 0 0 0
Sample Output1
2
0

cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
#include<set>
#include<vector>

int a[1000005];
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 0; i <= n; ++i)scanf("%d", &a[i]);
int ans = 0;//表示论文数
//从后往前贪心
for (int i = n; i >= 0; --i) {
ans += a[i];
//如果不满足题目条件
if (i <= ans) {
printf("%d\n", i);
break;
}
}
}
return 0;
}

B - 目を見てこれからのことを話そう

The h-index of an author is the largest h where he has at least hh papers with citations not less than h.
Bobo has no papers and he is going to publish some subsequently.
If he works on a paper for xx hours, the paper will get (ax) citations, where a is a known constant.
It’s clear that x should be a positive integer.
There is also a trick — one can cite his own papers published earlier.
Given Bobo has n working hours, find the maximum h-index of him.
Input
The input consists of several test cases and is terminated by end-of-file.
Each test case contains two integers n and a.
Output
For each test case, print an integer which denotes the maximum h-index.
Constraint
1n109
0an
The number of test cases does not exceed 104.
Sample Input
3 0
3 1
1000000000 1000000000
Sample Output
1
2
1000000000
Hint
For the first sample, Bobo can work 3 papers for 1 hour each.
With the trick mentioned, he will get papers with citations 2,1,0. Thus, his h-index is 1.
For the second sample, Bobo can work 2 papers for 1 and 2 hours respectively. He will get papers with citations 1+1,2+0. Thus, his h-index is 2

最优解是每个论文都花1小时。仔细想一想就出来了。

cpp
1
2
3
4
5
6
7
8
9
#include<iostream>
using namespace std;
int main() {
int n, a;
while (~scanf("%d%d", &n, &a)) {
printf("%d\n", (n + a) >> 1);
}
return 0;
}

F - my wish かなえたいのに

Bobo has n tuples (a1,b1,c1),(a2,b2,c2),(an,bn,cn).
He would like to find the lexicographically smallest permutation p1,p2,,pn
of 1,2,,n.
such that for i{2,3,,n}
it holds that

api1+bpi1api1+bpi1+cpi1api+bpiapi+bpi+cpi

Input
The input consists of several test cases and is terminated by end-of-file. The first line of each test case contains an integer n.
The ith of the following nn lines contains 3 integers ai,bi and ci.
Output
For each test case, print nn integers p1,p2,,pn seperated by spaces. DO NOT print trailing spaces.
Constraint
1n103
1ai,bi,ci2×109
The sum of nn does not exceed 10^4
Sample Input
2
1 1 1
1 1 2
2
1 1 2
1 1 1
3
1 3 1
2 2 1
3 1 1
Sample Output
2 1
1 2
1 2 3

除法化乘法避免精度损失,在优化一下乘法(卡long long上限)。

cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
struct Node {
long long a, b, c;
int node;
};
Node Data[1001];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; ++i) {
scanf("%lld%lld%lld", &Data[i].a, &Data[i].b, &Data[i].c);
Data[i].node = i;
}
sort(Data + 1, Data + n + 1, [](Node&Left, Node&Right) {
long long&&left = (Left.a + Left.b)*(Right.c),
&&right = (Left.c)*(Right.a + Right.b);
return (left == right ? Left.node < Right.node:left < right);
});
for (int i = 1; i < n; ++i) {
printf("%lld ", Data[i].node);
}
printf("%lld", Data[n].node);
putchar('\n');
}
return 0;
}

G - すべては God knows…

Bobo has a string S=s1s2…sn consists of letter a, b and c.
He can transform the string by inserting or deleting substrings aa, bb and abab.
Formally, A=u∘w∘v (`∘'' denotes string concatenation) can be transformed into A′=u∘v and vice versa where u, v are (possibly empty) strings and w∈{aa,bb,abab}. Given the target string $T=t_1t_2\cdots t_m$, determine if Bobo can transform the string S into T. Input The input consists of several test cases and is terminated by end-of-file. The first line of each test case contains a string $s_1s_2\cdots s_n$. The second line contains a string $t_1t_2\cdots t_m$. Output For each test case, printYesif Bobo can. PrintNootherwise. Constraint $1≤n,m≤10^4$ $s_1,s_2,\cdots ,s_n,t_1,t_2,\cdots ,t_m∈\{a,b,c\}$ The sum of n and m does not exceed 250,000. Sample Input ab ba ac ca a ab Sample Output Yes No No Hint For the first sample, Bobo can transform asab => aababb => babb => ba`.

根据提示,ab可以转为baba同理。且可以增加删除aabb,那么,在没有c的字符串中,只要统计两个字符串中ab个数是否同奇同偶即可。而对于c,可以看作c将字符串分割成了若干子串。

cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<string>
#define scanf scanf_s
int ans1[10001], ans2[10001];
using namespace std;string a, b;

int main() {
while (cin >> a >> b) {
int t = 0;
int ct = 0;
for (int i = 0; i < a.size(); ++i) {
if (a[i] == 'c') {
ans1[ct++] = t;
}
else {
t ^= a[i];
}
}
ans1[ct++] = t;
int s = 0;
int st = 0;
for (int i = 0; i<b.size(); ++i) {
if (b[i] == 'c') {
ans2[st++] = s;
}
else {
s ^= b[i];
}
}
ans2[st++] = s;
bool flag = false;
if (st == ct) {
for (int i = 0; i < st; ++i) {
if (ans1[i] != ans2[i]) {
puts("No");
flag = true;
break;
}
}
if (!flag) {
puts("Yes");
}
}
else {
puts("No");
}
}
return 0;
}

K - 傷跡なぞる

Given a,b,c,d find out the number of pairs of integers (x,y) where axb,cyd and xy is a multiple of 2018.
Input
The input consists of several test cases and is terminated by end-of-file.
Each test case contains four integers a,b,c,d.
Output
For each test case, print an integer which denotes the result.
Constraint
1ab109,1cd109
The number of tests cases does not exceed 104.
Sample Input
1 2 1 2018
1 2018 1 2018
1 1000000000 1 1000000000
Sample Output
3
6051
1485883320325200

2018的公约数只有1*2018以及2*1009这两对,根据容斥定理很容易求出结果。

cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<set>
#include<vector>
using namespace std;
long long a, b, c, d;
int main() {
while (~scanf("%lld%lld%lld%lld", &a, &b, &c, &d)) {
long long left[4], right[4];

auto fuck = [](long long Array[4],long long &left,long long &right)->void {
Array[0] = right - left + 1;
Array[1] = right / 2 - (left - 1) / 2;
Array[2] = right / 1009 - (left - 1) / 1009;
Array[3] = right / 2018 - (left - 1) / 2018;
Array[2] -= Array[3];
Array[1] -= Array[3];
Array[0] -= Array[3] + Array[2] + Array[1];
};

fuck(left, a, b);
fuck(right, c, d);

const long long&&Ans =
left[0] * right[3] +
left[1] * (right[2] + right[3]) +
left[2] * (right[1] + right[3]) +
left[3] * (right[0] + right[1] + right[2] + right[3]);

printf("%lld\n", Ans);
}
return 0;
}