A - Happy Birthday!


Time limit : 2sec / Memory limit : 1000MB

Score: 100 points

Problem Statement

E869120's and square1001's 16-th birthday is coming soon.
Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.

E869120 and square1001 were just about to eat A and B of those pieces, respectively,
when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".

Can both of them obey the instruction in the note and take desired numbers of pieces of cake?

Constraints

  • A and B are integers between 1 and 16 (inclusive).
  • A+B is at most 16.

Input

Input is given from Standard Input in the following format:

A B

Output

If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay!; otherwise, print :(.


Sample Input 1

Copy
5 4

Sample Output 1

Copy
Yay!

Both of them can take desired number of pieces as follows: 


Sample Input 2

Copy
8 8

Sample Output 2

Copy
Yay!

Both of them can take desired number of pieces as follows: 


Sample Input 3

Copy
11 4

Sample Output 3

Copy
:(

In this case, there is no way for them to take desired number of pieces, unfortunately.

代码:

import java.util.*;

public class Main {

    public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
if(a <= && b <= )System.out.println("Yay!");
else System.out.println(":(");
}
}

B - Ringo's Favorite Numbers


Time limit : 2sec / Memory limit : 1000MB

Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.
As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly Dtimes.

Find the N-th smallest integer that would make Ringo happy.

Constraints

  • D is 01 or 2.
  • N is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.


Sample Input 1

Copy
0 5

Sample Output 1

Copy
5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1234567, ...
Thus, the 5-th smallest integer that would make Ringo happy is 5.


Sample Input 2

Copy
1 11

Sample Output 2

Copy
1100

The integers that can be divided by 100 exactly once are as follows: 1002003004005006007008009001 0001 100, ...
Thus, the integer we are seeking is 1 100.


Sample Input 3

Copy
2 85

Sample Output 3

Copy
850000

The integers that can be divided by 100 exactly twice are as follows: 10 00020 00030 000, ...
Thus, the integer we are seeking is 850 000.

import java.util.*;

public class Main {

    public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int d = in.nextInt();
int n = in.nextInt();
int s = ;
for(int i = ;i < d;i ++) {
s *= ;
}
if(n == )n ++;
System.out.println(s * n);
}
}

C - *3 or /2


Time limit : 2sec / Memory limit : 1000MB

Score: 300 points

Problem Statement

As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length Na={a1,a2,a3,…,aN}.
Snuke, an employee, would like to play with this sequence.

Specifically, he would like to repeat the following operation as many times as possible:

For every i satisfying 1≤iN, perform one of the following: "divide ai by 2" and "multiply ai by 3".
Here, choosing "multiply ai by 3" for every i is not allowed, and the value of ai after the operation must be an integer.

At most how many operations can be performed?

Constraints

  • N is an integer between 1 and 10 000 (inclusive).
  • ai is an integer between 1 and 1 000 000 000 (inclusive).

Input

Input is given from Standard Input in the following format:

N
a1 a2 a3 aN

Output

Print the maximum number of operations that Snuke can perform.


Sample Input 1

Copy
3
5 2 4

Sample Output 1

Copy
3

The sequence is initially 5,2,4. Three operations can be performed as follows:

  • First, multiply a1 by 3, multiply a2 by 3 and divide a3 by 2. The sequence is now 15,6,2.
  • Next, multiply a1 by 3, divide a2 by 2 and multiply a3 by 3. The sequence is now 45,3,6.
  • Finally, multiply a1 by 3, multiply a2 by 3 and divide a3 by 2. The sequence is now 135,9,3.

Sample Input 2

Copy
4
631 577 243 199

Sample Output 2

Copy
0

No operation can be performed since all the elements are odd. Thus, the answer is 0.


Sample Input 3

Copy
10
2184 2126 1721 1800 1024 2528 3360 1945 1280 1776

Sample Output 3

Copy
39
算一下每个数可以被2整除多少次,总次数。
代码:
import java.util.*;

public class Main {

    public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int d,m = 0;
for(int i = 0;i < n;i ++) {
d = in.nextInt();
while(d % 2 == 0) {
d /= 2;
m ++;
}
}
System.out.println(m);
}
}

D - Patisserie ABC


Time limit : 2sec / Memory limit : 1000MB

Score: 400 points

Problem Statement

Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100.

The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The i-th kind of cake has the beauty of xi, the tastiness of yi and the popularity of zi.
These values may be zero or negative.

Ringo has decided to have M pieces of cakes here. He will choose the set of cakes as follows:

  • Do not have two or more pieces of the same kind of cake.
  • Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).

Find the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.

Constraints

  • N is an integer between 1 and 1 000 (inclusive).
  • M is an integer between 0 and N (inclusive).
  • xi,yi,zi (1≤iN) are integers between −10 000 000 000 and 10 000 000 000 (inclusive).

Input

Input is given from Standard Input in the following format:

N M
x1 y1 z1
x2 y2 z2
: :
xN yN zN

Output

Print the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.


Sample Input 1

Copy
5 3
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9

Sample Output 1

Copy
56

Consider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:

  • Beauty: 1+3+9=13
  • Tastiness: 5+5+7=17
  • Popularity: 9+8+9=26

The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 13+17+26=56. This is the maximum value.


Sample Input 2

Copy
5 3
1 -2 3
-4 5 -6
7 -8 -9
-10 11 -12
13 -14 15

Sample Output 2

Copy
54

Consider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:

  • Beauty: 1+7+13=21
  • Tastiness: (−2)+(−8)+(−14)=−24
  • Popularity: 3+(−9)+15=9

The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 21+24+9=54. This is the maximum value.


Sample Input 3

Copy
10 5
10 -80 21
23 8 38
-94 28 11
-26 -2 18
-69 72 79
-26 -86 -54
-72 -50 59
21 65 -32
40 -94 87
-62 18 82

Sample Output 3

Copy
638

If we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total beauty, tastiness and popularity will be −32366 and 249, respectively.
The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 323+66+249=638. This is the maximum value.


Sample Input 4

Copy
3 2
2000000000 -9000000000 4000000000
7000000000 -5000000000 3000000000
6000000000 -1000000000 8000000000

Sample Output 4

Copy
30000000000

The values of the beauty, tastiness and popularity of the cakes and the value to be printed may not fit into 32-bit integers.

n个蛋糕选m个,要求三项值,每一项的和的绝对值加到一起最大,对于每一项,要么和是正的,要么和是负的取绝对值,一共三项,共八种情况,进行枚举,每个蛋糕八种情况的三项和,排序后,选前m大的,进行更新最大值。

二进制位是1就是和为正,是0就和为负(即把这一项的值当成负的减去变为正的,如果这一项本来就是正的,减去了会更小,肯定不满足,会被值大的情况覆盖掉)。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long va[][];
int main() {
int n,m,i,j,k;
scanf("%d%d",&n,&m);
for (i = ;i < n;i ++) {
for (j = ;j < ;j ++)
scanf("%lld",&va[i][j]);
}
long long ans = -;
for (i = ;i < ;i ++) {
long long sum[];///记录每个蛋糕三项和
for (j = ;j < n;j ++) {
sum[j] = ;///i状态下 sum初始为0
for (k = ;k < ;k ++) {
if(i >> k & )sum[j] += va[j][k];///对应位是1直接加
else sum[j] -= va[j][k];///否则减,如果结果真的是负的,减去负的就是正的
}
}
sort(sum,sum + n);///默认升序排顺序
long long tans = ;
for (j = ;j <= m;j ++)
tans += sum[n - j];///从后往前加m个大的
ans = max(tans,ans);///更新
}
printf("%lld",ans);
return ;
}

AtCoder Beginner Contest 100 2018/06/16的更多相关文章

  1. AtCoder Beginner Contest 106 2018/08/18

    A - Garden Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement There is a ...

  2. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  5. AtCoder Beginner Contest 068 ABCD题

    A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...

  6. AtCoder Beginner Contest 154 题解

    人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...

  7. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  8. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  9. AtCoder Beginner Contest 169 题解

    AtCoder Beginner Contest 169 题解 这场比赛比较简单,证明我没有咕咕咕的时候到了! A - Multiplication 1 没什么好说的,直接读入两个数输出乘积就好了. ...

随机推荐

  1. Laravel 5.4的本地化

    简介 Laravel 的本地化功能提供方便的方法来获取多语言的字符串,让你的网站可以简单的支持多语言. 语言包存放在 resources/lang 目录下的文件里.在此目录中应该有应用对应支持的语言并 ...

  2. 封装CLLocationManager定位获取经纬度

    创建调用方法,在.h文件里 #import <Foundation/Foundation.h> @interface RMMapLocation : NSObject { void (^s ...

  3. python coding style guide 的高速落地实践

    python coding style guide 的高速落地实践 机器和人各有所长,如coding style检查这样的可自己主动化的工作理应交给机器去完毕,故发此文帮助你在几分钟内实现coding ...

  4. 2018年EMUI系统能力分论坛来啦

    为鼓励开发者创新,挖掘前沿创新能力的应用及服务,帮开发者打造爆款应用的同时丰富终端消费者的用户体验,由设立10亿激励基金耀星计划扶持的华为创新竞赛平台即将开启. 竞赛平台将滚动推出AI.HAG.AR. ...

  5. linux下proc里关于磁盘性能的参数(转)

    我们在磁盘写操作持续繁忙的服务器上曾经碰到一个特殊的性能问题.每隔 30 秒,服务器就会遇到磁盘写活动高峰,导致请求处理延迟非常大(超过3秒).后来上网查了一下资料,通过调整内核参数,将写活动的高峰分 ...

  6. nginx配置1:借助Nginx搭建反向代理服务器与缓存静态文件

    修改配置文件nginx.conf (1)进程数与每个进程的最大连接数: •nginx进程数,建议设置为等于CPU总核心数 •单个进程最大连接数,那么该服务器的最大连接数=连接数*进程数 (2)Ngin ...

  7. ubuntu 安装 pygame 很好玩的东西

    1. 简介 pygame 是基于对 SDL库的python 封装,提供python接口.SDL(Simple DirectMedia Layer) 是一个跨平台的游戏开发库,方便游戏开发和移植.目前最 ...

  8. javascript中replace( )方法的使用——有博主已经讲过了,但里面有一小丢丢知识错误,挺重要的部分,我就重提下,以免初学者弄错

    阿里面试题:说出以下函数的作用是?空白区域应该填写什么? 其实这个问题http://www.phpstudy.net/b.php/105983.html解释的已经非常好了,思路也很顺,容易理解,本文将 ...

  9. JVM GC调优一则--增大Eden Space提高性能

    版权声明:本文为横云断岭原创文章,未经博主同意不得转载.微信公众号:横云断岭的专栏 https://blog.csdn.net/hengyunabc/article/details/24924843 ...

  10. Django的模型层(2)---多表操作

    多表操作 创建模型 实例:我们来假定下面这些概念,字段和关系 作者模型:一个作者有姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息.作者详情模型和作者模型之间是一对 ...