我是靠谱客的博主 纯情咖啡豆,最近开发中收集的这篇文章主要介绍Atcoder contest081,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

https://abc081.contest.atcoder.jp/tasks/abc081_a

A - Placing Marbles


Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

Snuke has a grid consisting of three squares numbered 12 and 3. In each square, either 0 or 1 is written. The number written in Square i is si.

Snuke will place a marble on each square that says 1. Find the number of squares on which Snuke will place a marble.

Constraints

  • Each of s1s2 and s3 is either 1 or 0.

Input

Input is given from Standard Input in the following format:

s1s2s3

Output

Print the answer.


Sample Input 1

Copy
101

Sample Output 1

Copy
2
  • A marble will be placed on Square 1 and 3.

Sample Input 2

Copy
000

Sample Output 2

Copy
0
  • No marble will be placed on any square.
  • 题意:统计1的个数
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    char a[5];
    cin>>a;
    int ans=0;
    for(int i=0;i<3;i++){
        if(a[i]=='1') ans++;
    }
    cout<<ans<<endl;
        return 0;
}

B - Shift only


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

There are N positive integers written on a blackboard: A1,…,AN.

Snuke can perform the following operation when all integers on the blackboard are even:

  • Replace each integer X on the blackboard by X divided by 2.

Find the maximum possible number of operations that Snuke can perform.

Constraints

  • 1≤N≤200
  • 1≤Ai≤109

Input

Input is given from Standard Input in the following format:

N
A1 A2 ... AN

Output

Print the maximum possible number of operations that Snuke can perform.


Sample Input 1

Copy
3
8 12 40

Sample Output 1

Copy
2

Initially, [8,12,40] are written on the blackboard. Since all those integers are even, Snuke can perform the operation.

After the operation is performed once, [4,6,20] are written on the blackboard. Since all those integers are again even, he can perform the operation.

After the operation is performed twice, [2,3,10] are written on the blackboard. Now, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.

Thus, Snuke can perform the operation at most twice.


Sample Input 2

Copy
4
5 6 8 10

Sample Output 2

Copy
0

Since there is an odd number 5 on the blackboard already in the beginning, Snuke cannot perform the operation at all.


Sample Input 3

Copy
6
382253568 723152896 37802240 379425024 404894720 471526144

Sample Output 3

Copy
8

题意:n个数,全体元素能被2整除的次数
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5 typedef long long ll;
 6 ll a[210];
 7 ll sum=0;
 8 int judge(ll n){
 9     ll ans=0;
10     for(int i=0;i<n;i++){
11         if(a[i]==0) return sum;
12         if(a[i]%2==0) {
13         ans++;
14         a[i]=a[i]/2;
15         }
16         else return sum;
17     }
18     if(ans==n) {
19         sum++;
20         judge(ans);
21     }
22     else return sum;
23 }
24 int main(){
25     ios::sync_with_stdio(0);
26     ll n;
27     cin>>n;
28     memset(a,0,sizeof(a));
29     for(int i=0;i<n;i++){
30         cin>>a[i];
31         if(a[i]==0) return 0;
32     }
33     ll m=judge(n);
34     cout<<m<<endl;
35         return 0;
36 }

C - Not so Diverse


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

Takahashi has N balls. Initially, an integer Ai is written on the i-th ball.

He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.

Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Constraints

  • 1≤KN≤200000
  • 1≤AiN
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A1 A2 ... AN

Output

Print the minimum number of balls that Takahashi needs to rewrite the integers on them.


Sample Input 1

Copy
5 2
1 1 2 2 5

Sample Output 1

Copy
1

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2. On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.


Sample Input 2

Copy
4 4
1 1 2 2

Sample Output 2

Copy
0

Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.


Sample Input 3

Copy
10 3
5 1 3 2 4 1 1 2 3 4

Sample Output 3

Copy
3

因为不同的元素数最多不超过k个,超过要修改,为了省力,肯定修改相等元素数少的,
首先要记录下来,每个不同元素的重复数,然后降序排序,k后就是需要修改的数量
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #include <set>
 6 using namespace std;
 7 typedef long long ll;
 8 int a[200005];
 9 bool compare(int a,int b){
10     return a>b;
11 }
12 int main(){
13     ios::sync_with_stdio(0);
14     int n,k,x;
15     cin>>n>>k;
16     memset(a,0,sizeof(a));
17     for(int i=0;i<n;i++){
18         cin>>x;
19         a[x]++;
20     }
21     int ans=0;
22     sort(a,a+n,compare);
23     for(int i=k;i<=n;i++){
24         ans+=a[i];
25     }
26     cout<<ans<<endl;
27     return 0;
28 }

 

D - Non-decreasing


Time limit : 2sec / Memory limit : 256MB

Score : 600 points

Problem Statement

Snuke has an integer sequence, a, of length N. The i-th element of a (1-indexed) is ai.

He can perform the following operation any number of times:

  • Operation: Choose integers x and y between 1 and N (inclusive), and add ax to ay.

He would like to perform this operation between 0 and 2N times (inclusive) so that a satisfies the condition below. Show one such sequence of operations. It can be proved that such a sequence of operations always exists under the constraints in this problem.

  • Condition: a1≤a2≤…≤aN

Constraints

  • 2≤N≤50
  • −106≤ai≤106
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
a1 a2  aN

Output

Let m be the number of operations in your solution. In the first line, print m. In the i-th of the subsequent m lines, print the numbers x and y chosen in the i-th operation, with a space in between. The output will be considered correct if m is between 0 and 2N (inclusive) and a satisfies the condition after the m operations.


Sample Input 1

Copy
3
-2 5 -1

Sample Output 1

Copy
2
2 3
3 3
  • After the first operation, a=(−2,5,4).
  • After the second operation, a=(−2,5,8), and the condition is now satisfied.

Sample Input 2

Copy
2
-1 -3

Sample Output 2

Copy
1
2 1
  • After the first operation, a=(−4,−3) and the condition is now satisfied.

Sample Input 3

Copy
5
0 0 0 0 0

Sample Output 3

Copy
0
  • The condition is satisfied already in the beginning.
  • 题意:给定一个元素数为n的序列,要求在2n的操作内把该序列变成一个非递减序列 
         对于一个非负序列,循环a[i+1]+=a[i]即可。
         对于一个非正序列,循环a[i]+=a[i+1]即可。
         对于其他序列,考虑将其转化成上述两种序列。
        遍历序列,如果最大值是负数,就从后往前遍历,如是正数则从前往后遍历     
        时间复杂度O(N).
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main(){
 5     ios::sync_with_stdio(0);
 6     int n;
 7     cin>>n;
 8     std::vector<ll> a(n);
 9     int p=0;
10     for(int i=0;i<n;i++){
11         cin>>a[i];
12         if(abs(a[p])<abs(a[i])){
13             p=i;
14         }
15     }
16     cout<<2*n-1<<endl;
17     for(int i=0;i<n;i++){
18         cout<<p+1<<" "<<i+1<<endl;
19     }
20     if(a[p]<0){
21         for(int i=n;i>1;i--){
22             cout<<i<<" "<<i-1<<endl;
23         }
24     }else{
25         for(int j=1;j<n;j++){
26             cout<<j<<" "<<j+1<<endl;
27         }
28     }
29         return 0;
30 }

 



转载于:https://www.cnblogs.com/z-712/p/8022550.html

最后

以上就是纯情咖啡豆为你收集整理的Atcoder contest081的全部内容,希望文章能够帮你解决Atcoder contest081所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部