AtCoder ABC 306 解析

目录

A - Echo

B - Base 2 

C - Centers

D - Poisonous Full-Course 


A - Echo

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100100 points

Problem Statement

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.

Constraints

  • NN is an integer such that 1 \le N \le 501≤N≤50.
  • SS is a string of length NN consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

NN
SS

Output

Print the answer.


Sample Input 1

8
beginner

Sample Output 1

bbeeggiinnnneerr

It is the same as the example described in the problem statement.


Sample Input 2

Copy

3
aaa

Sample Output 2

Copy

aaaaaa

可以定义一个变量来存储要打印的字符串,但在竞争性编程中,所需的只是正确的输出,因此您可以放松并实现以下内容:

用for语句迭代S的每个字符,并打印两次。

在这里,您必须小心,不要打印不必要的空格或换行符。

#include<bits/stdc++.h>

using namespace std;

int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i=0;i<n;i++){
    cout << s[i] << s[i];
  }cout << "\n";
  return 0;
}

B - Base 2 


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200 points

Problem Statement

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}A0​20+A1​21+⋯+A63​263.

Constraints

  • A_iAi​ is 00 or 11.

Input

The input is given from Standard Input in the following format:

A_0A0​ A_1A1​ \dots… A_{63}A63​

Output

Print the answer as an integer.


Sample Input 1

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

Sample Output 1 

13

A_0 2^0 + A_1 2^1 + \dots + A_{63} 2^{63} = 2^0 + 2^2 + 2^3 = 13A0​20+A1​21+⋯+A63​263=20+22+23=13.


Sample Input 2 

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

Sample Output 2 

766067858140017173

使用for语句查找问题语句中所述的答案。与下面的示例代码一样,如果您使用位移位运算符,那么实现将非常简洁。请注意,有符号的64位整数(如C++中的整数)不适用于此问题,因为它最多只能表示长263−1。(请使用无符号64位整数或bigint。)

#include<bits/stdc++.h>

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;
}


C - Centers


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 250250 points

Problem Statement

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.

  • Suppose that those jj such that A_j = iAj​=i are j=\alpha,\beta,\gamma\ (\alpha < \beta < \gamma)j=α,β,γ (α<β<γ). Then, f(i) = \betaf(i)=β.

Constraints

  • 1\leq N \leq 10^51≤N≤105
  • 1 \leq A_j \leq N1≤Aj​≤N
  • ii occurs in AA exactly three times, for each i=1,2,\dots,Ni=1,2,…,N.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN
A_1A1​ A_2A2​ \dots… A_{3N}A3N​

Output

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.


Sample Input 1

3
1 1 3 2 3 2 2 3 1

Sample Output 1 

1 3 2
  • 11 occurs in AA at A_1,A_2,A_9A1​,A2​,A9​, so f(1) = 2f(1)=2.
  • 22 occurs in AA at A_4,A_6,A_7A4​,A6​,A7​, so f(2) = 6f(2)=6.
  • 33 occurs in AA at A_3,A_5,A_8A3​,A5​,A8​, so f(3) = 5f(3)=5.

Thus, f(1) < f(3) < f(2)f(1)<f(3)<f(2), so 1,31,3, and 22 should be printed in this order.


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

解析:其实可以使用以下算法进行求解。准备一个空数组ans。按A的顺序扫描序列在这里,我们在另一个数组中维护到目前为止,每个数字在我们扫描的零件中发生了多少次。设c是您正在检查的整数。如果这是c的第二次出现,请将c附加到ans的尾部。打印ans。该算法在总共O(N)个时间内工作,这是足够快的。

#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> cnt(n + 1), ans;
    for (int i = 0; i < 3 * n; i++) {
        int a;
        cin >> a;
        ++cnt[a];
        if (cnt[a] == 2) ans.push_back(a);
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << (i == n - 1 ? '\n' : ' ');
    }
}


D - Poisonous Full-Course 

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 400400 points

Problem Statement

Takahashi has decided to enjoy a wired full-course meal consisting of NN courses in a restaurant.
The ii-th course is:

  • if X_i=0Xi​=0, an antidotal course with a tastiness of Y_iYi​;
  • if X_i=1Xi​=1, a poisonous course with a tastiness of Y_iYi​.

When Takahashi eats a course, his state changes as follows:

  • Initially, Takahashi has a healthy stomach.
  • When he has a healthy stomach,
    • if he eats an antidotal course, his stomach remains healthy;
    • if he eats a poisonous course, he gets an upset stomach.
  • When he has an upset stomach,
    • if he eats an antidotal course, his stomach becomes healthy;
    • if he eats a poisonous course, he dies.

The meal progresses as follows.

  • Repeat the following process for i = 1, \ldots, Ni=1,…,N in this order.
    • First, the ii-th course is served to Takahashi.
    • Next, he chooses whether to "eat" or "skip" the course.
      • If he chooses to "eat" it, he eats the ii-th course. His state also changes depending on the course he eats.
      • If he chooses to "skip" it, he does not eat the ii-th course. This course cannot be served later or kept somehow.
    • Finally, (if his state changes, after the change) if he is not dead,
      • if i \neq Ni=N, he proceeds to the next course.
      • if i = Ni=N, he makes it out of the restaurant alive.

An important meeting awaits him, so he must make it out of there alive.
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

  • All input values are integers.
  • 1 \le N \le 3 \times 10^51≤N≤3×105
  • X_i \in \{0,1\}Xi​∈{0,1}
    • In other words, X_iXi​ is either 00 or 11.
  • -10^9 \le Y_i \le 10^9−109≤Yi​≤109

Input

The input is given from Standard Input in the following format:

NN
X_1X1​ Y_1Y1​
X_2X2​ Y_2Y2​
\vdots⋮
X_NXN​ Y_NYN​

Output

Print the answer as an integer.


Sample Input 1

5
1 100
1 300
0 -200
1 500
1 300

Sample Output 1

600

The following choices result in a total tastiness of the courses that he eats amounting to 600600, which is the maximum possible.

  • He skips the 11-st course. He now has a healthy stomach.
  • He eats the 22-nd course. He now has an upset stomach, and the total tastiness of the courses that he eats amounts to 300300.
  • He eats the 33-rd course. He now has a healthy stomach again, and the total tastiness of the courses that he eats amounts to 100100.
  • He eats the 44-th course. He now has an upset stomach, and the total tastiness of the courses that he eats amounts to 600600.
  • He skips the 55-th course. He now has an upset stomach.
  • In the end, he is not dead, so he makes it out of the restaurant alive.

Sample Input 2

4
0 -1
1 -2
0 -3
1 -4

Sample Output 2

0

For this input, it is optimal to eat nothing, in which case the answer is 00.


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

The answer may not fit into a 3232-bit integer type.

考虑用动态编程(DP)来解决这个问题。我们应该维护什么商店?

直截了当地说,这个问题可以通过填写下面的DP表来解决。dp[过程][高桥状态]当他决定是吃还是跳过前i道菜时,他吃过的菜的最大总味道是j(0……他有一个健康的胃,1……他胃不舒服。)如果你不能解决这个问题,考虑到上面“如何定义DP表”,试着在考虑“转换应该如何”的同时实现。这是DP的一个很好的练习。

#include<bits/stdc++.h>

using namespace std;

long long dp[300005][2];

int main(){
  long long n;
  cin >> n;
  vector<long long> x(n),y(n);
  for(long long i=0;i<n;i++){
    cin >> x[i] >> y[i];
  }

  for(long long i=0;i<=n;i++){
    dp[i][0]=-4e18;
    dp[i][1]=-4e18;
  }
  dp[0][0]=0;

  for(long long i=0;i<n;i++){
    if(x[i]==0){
      dp[i+1][0]=max(dp[i][0],max(dp[i][0],dp[i][1])+y[i]);
    }
    else{
      dp[i+1][1]=max(dp[i][1],dp[i][0]+y[i]);
    }

    dp[i+1][0]=max(dp[i+1][0],dp[i][0]);
    dp[i+1][1]=max(dp[i+1][1],dp[i][1]);
  }
  cout << max(dp[n][0],dp[n][1]) << "\n";
  return 0;
}

本人因实力比较差只能写到d。有不足大家多多指教。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: atcoder beginner contest 235 是一场由 AtCoder 组织的初学者比赛,旨在为初学者提供一个锻炼自己编程能力的平台。比赛通常包括多个问题,参赛者需要在规定时间内解决这些问题。比赛难度逐渐增加,从而帮助参赛者提高自己的编程技能。 ### 回答2: ATCoder Beginner Contest 235(简称ABC 235)是一项由ATCoder举办的编程竞赛。该比赛旨在为初学者提供一个机会展示他们的编程技巧和解决问题的能力。 ABC 235通常由4个问题组成,题目难度递增。参赛者需要在规定的时间内使用编程语言解决这些问题。这些问题通常涵盖了各种编程相关的主题,例如数学问题、字符串处理、排序和搜索算法等。 在比赛开始前,参赛者将获得一份题目说明文档和输入样例。他们需要根据题目要求编写程序,处理给定的输入数据,并生成相应的输出。比赛时间一般为2-3小时,参赛者需要尽可能快速且准确地解决问题。 评判将根据参赛者的程序输出与预期结果的一致性进行。参赛者可以在比赛过程中提交多次解答,但只有第一次正确答案会被记入最终的成绩。 ABC 235不仅提供了一个竞赛平台,还鼓励参赛者通过讨论和分享解题思路来学习和提高。在比赛结束后,ATCoder将提供详细的解题分析和解题报告,帮助参赛者了解每个题目的最佳解决方法,并提供参考答案和示例代码。 通过参加ATCoder Beginner Contest 235,参赛者可以提升他们的编程技能,锻炼逻辑思维能力,并与全球的编程爱好者交流。无论是初学者还是有经验的编程者,ABC 235都是一个很好的学习和挑战的机会。 ### 回答3: AtCoder Beginner Contest 235 是一个在 AtCoder 上的初级比赛。该比赛通常会吸引很多新手程序员参加。它由 AtCoder 组织主办,旨在帮助新手提高编程技能以及在竞赛中锻炼自己。 比赛的题目难度由易到难,共有四个问题。通常,第一个问题是一个简单的数学问题,要求解决一个简单的算术运算。第二个问题可能是一个字符串操作问题,需要对给定的字符串进行处理。第三个问题可能是一个动态规划或贪心算法问题,需要细心分析问题,找出最优解。最后一个问题通常是一个较难的图论或组合问题,需要一些高级算法来解决。 参赛选手在比赛开始后有一定的时间限制来解决这些问题。他们可以使用自己熟悉的编程语言来实现解决方案。然后他们将自己的程序提交到 AtCoder 的在线评测系统中进行评测。评测结果会即时显示,并将参赛选手的成绩排名和讨论解答过程的视频分享给其他选手。 参加 AtCoder Beginner Contest 235 对于新手来说是一个很好的机会。通过解决这些问题,他们可以练习编程技巧,提高解决问题的能力。比赛结束后,他们还可以看到其他选手的解答,学习他们的思路和方法。同时,比赛的排名和奖励也是一种鼓励和激励新手继续努力学习的方式。 总之,AtCoder Beginner Contest 235 是一个对于新手非常友好的比赛,它提供了一个锻炼和展示编程技能的平台。无论是对于新手还是更有经验的选手,参加这样的比赛都是一个宝贵的机会。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值