目录
A - Echo
B - Base 2
C - Centers
D - Poisonous Full-Course
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100100 points
You are given a string SS of length NN consisting of lowercase English letters.
We denote the ii-th character of SS by S_iSi.
Print the string of length 2N2N obtained by concatenating S_1,S_1,S_2,S_2,\dots,S_NS1,S1,S2,S2,…,SN, and S_NSN in this order.
For example, if SS is beginner
, print bbeeggiinnnneerr
.
The input is given from Standard Input in the following format:
NN SS
Print the answer.
8 beginner
bbeeggiinnnneerr
It is the same as the example described in the problem statement.
Copy
3 aaa
Copy
aaaaaa
可以定义一个变量来存储要打印的字符串,但在竞争性编程中,所需的只是正确的输出,因此您可以放松并实现以下内容:
用for语句迭代S的每个字符,并打印两次。
在这里,您必须小心,不要打印不必要的空格或换行符。
#include
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
for(int i=0;i
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200 points
You are given a sequence A=(A_0,A_1,\dots,A_{63})A=(A0,A1,…,A63) of length 6464 consisting of 00 and 11.
Find A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63}A020+A121+⋯+A63263.
The input is given from Standard Input in the following format:
A_0A0 A_1A1 \dots… A_{63}A63
Print the answer as an integer.
1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13
A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13A020+A121+⋯+A63263=20+22+23=13.
1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 0
766067858140017173
使用for语句查找问题语句中所述的答案。与下面的示例代码一样,如果您使用位移位运算符,那么实现将非常简洁。请注意,有符号的64位整数(如C++中的整数)不适用于此问题,因为它最多只能表示长263−1。(请使用无符号64位整数或bigint。)
#include
using namespace std;
using ll = unsigned long long;
int main() {
ll ans = 0;
for (int i = 0; i < 64; i++) {
ll a;
cin >> a;
ans += a << i;
}
cout << ans << endl;
}
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 250250 points
You are given a sequence A=(A_1,A_2,\dots,A_{3N})A=(A1,A2,…,A3N) of length 3N3N where each of 1,2,\dots1,2,…, and NN occurs exactly three times.
For i=1,2,\dots,Ni=1,2,…,N, let f(i)f(i) be the index of the middle occurrence of ii in AA. Sort 1,2,\dots,N1,2,…,N in ascending order of f(i)f(i).
Formally, f(i)f(i) is defined as follows.
The input is given from Standard Input in the following format:
NN A_1A1 A_2A2 \dots… A_{3N}A3N
Print the sequence of length NN obtained by sorting 1,2,\dots,N1,2,…,N in ascending order of f(i)f(i), separated by spaces.
3 1 1 3 2 3 2 2 3 1
1 3 2
Thus, f(1) < f(3) < f(2)f(1) 解析:其实可以使用以下算法进行求解。准备一个空数组ans。按A的顺序扫描序列在这里,我们在另一个数组中维护到目前为止,每个数字在我们扫描的零件中发生了多少次。设c是您正在检查的整数。如果这是c的第二次出现,请将c附加到ans的尾部。打印ans。该算法在总共O(N)个时间内工作,这是足够快的。 Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Takahashi has decided to enjoy a wired full-course meal consisting of NN courses in a restaurant. When Takahashi eats a course, his state changes as follows: The meal progresses as follows. An important meeting awaits him, so he must make it out of there alive. The input is given from Standard Input in the following format: Print the answer as an integer. The following choices result in a total tastiness of the courses that he eats amounting to 600600, which is the maximum possible. For this input, it is optimal to eat nothing, in which case the answer is 00. The answer may not fit into a 3232-bit integer type. 考虑用动态编程(DP)来解决这个问题。我们应该维护什么商店? 直截了当地说,这个问题可以通过填写下面的DP表来解决。dp[过程][高桥状态]当他决定是吃还是跳过前i道菜时,他吃过的菜的最大总味道是j(0……他有一个健康的胃,1……他胃不舒服。)如果你不能解决这个问题,考虑到上面“如何定义DP表”,试着在考虑“转换应该如何”的同时实现。这是DP的一个很好的练习。
Sample Input 2
1
1 1 1
Sample Output 2
1
Sample Input 3
4
2 3 4 3 4 1 3 1 1 4 2 2
Sample Output 3
3 4 1 2
#include
D - Poisonous Full-Course
Problem Statement
The ii-th course is:
Find the maximum possible sum of tastiness of the courses that he eats (or 00 if he eats nothing) when he decides whether to "eat" or "skip" the courses under that condition.Constraints
Input
NN
X_1X1 Y_1Y1
X_2X2 Y_2Y2
\vdots⋮
X_NXN Y_NYN
Output
Sample Input 1
5
1 100
1 300
0 -200
1 500
1 300
Sample Output 1
600
Sample Input 2
4
0 -1
1 -2
0 -3
1 -4
Sample Output 2
0
Sample Input 3
15
1 900000000
0 600000000
1 -300000000
0 -700000000
1 200000000
1 300000000
0 -600000000
1 -900000000
1 600000000
1 -100000000
1 -400000000
0 900000000
0 200000000
1 -500000000
1 900000000
Sample Output 3
4100000000
#include
本人因实力比较差只能写到d。有不足大家多多指教。