因为去了躺上海,导致两场牛客多校没有打。这场杭电多校在努力也只能写5题,有了大佬讲题解我就过一下。
Maximum Multiple
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Given an integer n, Chiaki would like to find three positive integers x, y and z such that: n=x+y+z, x∣n, y∣n, z∣n and xyz is maximum.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤106).
Output
For each test case, output an integer denoting the maximum xyz. If there no such integers, output −1 instead.
Sample Input
1 |
3 1 2 3
Sample Output
1 |
-1 -1 1
n/s+n/t+n/k=n;
求得 s=3 t=3 k=3 /s=2 t=1 k=1;这两种情况最小,然后暴力就行了
我的写法是打了个表,数据范围不大。
1001
1 | #include<iostream> |
1002
Balanced Sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Chiaki has n strings s1,s2,…,sn consisting of ‘(‘ and ‘)’. A string of this type is said to be balanced:
- if it is the empty string
- if A and B are balanced, AB is balanced,
if A is balanced, (A) is balanced.
Chiaki can reorder the strings and then concatenate them get a new string t. Let f(t) be the length of the longest balanced subsequence (not necessary continuous) of t. Chiaki would like to know the maximum value of f(t) for all possible t.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤105) — the number of strings.
Each of the next n lines contains a string si (1≤|si|≤105) consisting of (' and
)’.
It is guaranteed that the sum of all |si| does not exceeds 5×106.
Output
For each test case, output an integer denoting the answer.
Sample Input
1 |
2 1 )()(()( 2 ) )(
Sample Output
1 |
4 2
先处理字符串
把他简化最后所有字符串都会变成
)))(((
像这样的形式。
然后贪心一下每次选左边最长或者右边最长,都没有影响,反正是往两边添加,只要保证选的这个是一种的最大的就行。
1 | #include<iostream> |
1003
Triangle Partition
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Special Judge
Problem Description
Chiaki has 3n points p1,p2,…,p3n. It is guaranteed that no three points are collinear.
Chiaki would like to construct n disjoint triangles where each vertex comes from the 3n points.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤1000) — the number of triangle to construct.
Each of the next 3n lines contains two integers xi and yi (−109≤xi,yi≤109).
It is guaranteed that the sum of all n does not exceed 10000.
Output
For each test case, output n lines contain three integers ai,bi,ci (1≤ai,bi,ci≤3n) each denoting the indices of points the i-th triangle use. If there are multiple solutions, you can output any of them.
Sample Input
1 |
1 1 1 2 2 3 3 5
Sample Output
1 | 1 2 3 |
没啥好讲的,排个序从左到右反正不会交叉。
1 | #include <cstdio> |
1004
hiaki has an array of n positive integers. You are told some facts about the array: for every two elements ai and aj in the subarray al..r (l≤i<j≤r), ai≠ajholds.
Chiaki would like to find a lexicographically minimal array which meets the facts.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains two integers n and m (1≤n,m≤105) — the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (1≤li≤ri≤n).
It is guaranteed that neither the sum of all n nor the sum of all m exceeds 106.
Output
For each test case, output n integers denoting the lexicographically minimal array. Integers should be separated by a single space, and no extra spaces are allowed at the end of lines.
Sample Input
1 |
3 2 1 1 2 4 2 1 2 3 4 5 2 1 3 2 4
Sample Output
1 |
1 2 1 2 1 2 1 2 3 1 1
队友写的,看了一下,贪心,每次放最小的就行。
1 | #include <bits/stdc++.h> |
1007
Chiaki Sequence Revisited
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 428 Accepted Submission(s): 69
Problem Description
Chiaki is interested in an infinite sequence a1,a2,a3,…, which is defined as follows:
an={1an−an−1+an−1−an−2n=1,2n≥3
Chiaki would like to know the sum of the first n terms of the sequence, i.e. ∑i=1nai. As this number may be very large, Chiaki is only interested in its remainder modulo (109+7).
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤105), indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤1018).
Output
For each test case, output an integer denoting the answer.
Sample Input
1 |
10 1 2 3 4 5 6 7 8 9 10
Sample Output
1 |
1 2 4 6 9 13 17 21 26 32
打个表找规律,
1 2 3 4 5 6 7 8 9 10
2 2 1 3 1 2 1 4 1 2
各个数出现的次数就是这样,然后就是lowbit(i)次,然后二分找 到哪个数出现的数次数总和为n
然后再看一下 每次找的的数,x,你会发现,x总是在n/2附近。
1 | #include<iostream> |
1011
Time Zone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1646 Accepted Submission(s): 289
Problem Description
Chiaki often participates in international competitive programming contests. The time zone becomes a big problem.
Given a time in Beijing time (UTC +8), Chiaki would like to know the time in another time zone s.
Input
There are multiple test cases. The first line of input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:
The first line contains two integers a, b (0≤a≤23,0≤b≤59) and a string s in the format of “UTC+X’’, “UTC-X’’, “UTC+X.Y’’, or “UTC-X.Y’’ (0≤X,X.Y≤14,0≤Y≤9).
Output
For each test, output the time in the format of hh:mm (24-hour clock).
Sample Input
1 |
3 11 11 UTC+8 11 12 UTC+9 11 23 UTC+0
Sample Output
1 |
11:11 12:12 03:23
注意精度
1 | include<iostream> |