前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >AtCoder Beginner Contest 069【A,水,B,水,C,数学,D,暴力】

AtCoder Beginner Contest 069【A,水,B,水,C,数学,D,暴力】

作者头像
Angel_Kitty
发布于 2018-04-09 07:32:40
发布于 2018-04-09 07:32:40
1.2K00
代码可运行
举报
运行总次数:0
代码可运行

A - K-City


Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?

Constraints

  • 2≤n,m≤100

Input

Input is given from Standard Input in the following format:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
n m

Output

Print the number of blocks in K-city.


Sample Input 1

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3 4

Sample Output 1

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
6

There are six blocks, as shown below:


Sample Input 2

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
2 2

Sample Output 2

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1

There are one block, as shown below:


题目链接:http://abc069.contest.atcoder.jp/tasks/abc069_a

分析:结论就是ans=(a-1)*(b-1)

下面给出AC代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 inline int read()
 5 {
 6     int x=0,f=1;
 7     char ch=getchar();
 8     while(ch<'0'||ch>'9')
 9     {
10         if(ch=='-')
11             f=-1;
12         ch=getchar();
13     }
14     while(ch>='0'&&ch<='9')
15     {
16         x=x*10+ch-'0';
17         ch=getchar();
18     }
19     return x*f;
20 }
21 inline void write(int x)
22 {
23     if(x<0)
24     {
25         putchar('-');
26         x=-x;
27     }
28     if(x>9)
29     {
30         write(x/10);
31     }
32     putchar(x%10+'0');
33 }
34 int main()
35 {
36     int a,b;
37     cin>>a>>b;
38     cout<<(a-1)*(b-1)<<endl;
39     return 0;
40 }

B - i18n


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

The word internationalization is sometimes abbreviated to i18n. This comes from the fact that there are 18 letters between the first i and the last n.

You are given a string s of length at least 3 consisting of lowercase English letters. Abbreviate s in the same way.

Constraints

  • 3≤|s|≤100 (|s| denotes the length of s.)
  • s consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
s

Output

Print the abbreviation of s.


Sample Input 1

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
internationalization

Sample Output 1

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
i18n

Sample Input 2

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
smiles

Sample Output 2

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
s4s

Sample Input 3

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
xyz

Sample Output 3

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
x1z

题目链接:http://abc069.contest.atcoder.jp/tasks/abc069_b

分析:输出第一个,最后一个就好咯

下面给出AC代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 inline int read()
 5 {
 6     int x=0,f=1;
 7     char ch=getchar();
 8     while(ch<'0'||ch>'9')
 9     {
10         if(ch=='-')
11             f=-1;
12         ch=getchar();
13     }
14     while(ch>='0'&&ch<='9')
15     {
16         x=x*10+ch-'0';
17         ch=getchar();
18     }
19     return x*f;
20 }
21 inline void write(int x)
22 {
23     if(x<0)
24     {
25         putchar('-');
26         x=-x;
27     }
28     if(x>9)
29     {
30         write(x/10);
31     }
32     putchar(x%10+'0');
33 }
34 char s[105];
35 int main()
36 {
37     cin>>s;
38     int len=strlen(s);
39     cout<<s[0]<<len-2<<s[len-1]<<endl;
40     return 0;
41 }

C - 4-adjacent


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

We have a sequence of length N, a=(a1,a2,…,aN). Each ai is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

  • For each 1≤iN−1, the product of ai and ai+1 is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

  • 2≤N≤105
  • ai is an integer.
  • 1≤ai≤109

Input

Input is given from Standard Input in the following format:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
N
a1 a2 … aN

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.


Sample Input 1

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3
1 10 100

Sample Output 1

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Yes

One solution is (1,100,10).


Sample Input 2

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
4
1 2 3 4

Sample Output 2

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
No

It is impossible to permute a so that the condition is satisfied.


Sample Input 3

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3
1 4 1

Sample Output 3

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Yes

The condition is already satisfied initially.


Sample Input 4

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
2
1 1

Sample Output 4

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
No

Sample Input 5

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
6
2 7 1 8 2 8

Sample Output 5

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Yes

题目链接:http://abc069.contest.atcoder.jp/tasks/arc080_a

分析:统计4的倍数,2的倍数还有不是这两个的倍数的数,然后2个2的倍数等于4的倍数,然后就这样了!

下面给出AC代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 inline int read()
 5 {
 6     int x=0,f=1;
 7     char ch=getchar();
 8     while(ch<'0'||ch>'9')
 9     {
10         if(ch=='-')
11             f=-1;
12         ch=getchar();
13     }
14     while(ch>='0'&&ch<='9')
15     {
16         x=x*10+ch-'0';
17         ch=getchar();
18     }
19     return x*f;
20 }
21 inline void write(int x)
22 {
23     if(x<0)
24     {
25         putchar('-');
26         x=-x;
27     }
28     if(x>9)
29     {
30         write(x/10);
31     }
32     putchar(x%10+'0');
33 }
34 int main()
35 {
36     int n;
37     cin>>n;
38     int a=0,b=0,c=0;
39     for(int i=0;i<n;i++)
40     {
41         ll x;
42         x=read();
43         if(x%4==0)
44             a++;
45         else if(x%2==0)
46             b++;
47         else c++;
48     }
49     if(b>0)
50         c++;
51     if(a+1>=c)
52         cout<<"Yes"<<endl;
53     else 
54     cout<<"No"<<endl;
55     return 0;
56 }

D - Grid Coloring


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 1, 2, …, N. Here, the following conditions should be satisfied:

  • For each i (1≤iN), there are exactly ai squares painted in Color i. Here, a1+a2+…+aN=HW.
  • For each i (1≤iN), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.

Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.

Constraints

  • 1≤H,W≤100
  • 1≤NHW
  • ai≥1
  • a1+a2+…+aN=HW

Input

Input is given from Standard Input in the following format:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
H W
N
a1 a2 … aN

Output

Print one way to paint the squares that satisfies the conditions. Output in the following format:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
c11 … c1W
:
cH1 … cHW

Here, cij is the color of the square at the i-th row from the top and j-th column from the left.


Sample Input 1

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
2 2
3
2 1 1

Sample Output 1

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1 1
2 3

Below is an example of an invalid solution:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1 2
3 1

This is because the squares painted in Color 1 are not 4-connected.


Sample Input 2

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
3 5
5
1 2 3 4 5

Sample Output 2

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1 4 4 4 3
2 5 4 5 3
2 5 5 5 3

Sample Input 3

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1 1
1
1

Sample Output 3

Copy

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1

题目链接:http://abc069.contest.atcoder.jp/tasks/arc080_b

分析:从一个点可以到达其它所有的点,直接来一个水平填充好像就过了

下面给出AC代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 inline int read()
 5 {
 6     int x=0,f=1;
 7     char ch=getchar();
 8     while(ch<'0'||ch>'9')
 9     {
10         if(ch=='-')
11             f=-1;
12         ch=getchar();
13     }
14     while(ch>='0'&&ch<='9')
15     {
16         x=x*10+ch-'0';
17         ch=getchar();
18     }
19     return x*f;
20 }
21 inline void write(int x)
22 {
23     if(x<0)
24     {
25         putchar('-');
26         x=-x;
27     }
28     if(x>9)
29     {
30         write(x/10);
31     }
32     putchar(x%10+'0');
33 }
34 int w,h,n;
35 int s[105][105];
36 int cnt[10005];
37 int main()
38 {
39     h=read();
40     w=read();
41     n=read();
42     for(int i=1;i<=n;i++)
43         cnt[i]=read();
44     int k=1;
45     for(int i=1;i<=h;i++)
46     {
47         if(i%2==1)
48         {
49             for(int j=1;j<=w;j++)
50             {
51                 if(cnt[k]==0)
52                 k++;
53                 cnt[k]--;
54                 s[i][j]=k;
55             }
56         }
57     else
58     {
59         for(int j=w;j>0;j--)
60         {
61             if(cnt[k]==0)
62               k++;
63             cnt[k]--;
64             s[i][j]=k;
65         }
66     }
67     }
68     for(int i=1;i<=h;i++)
69     {
70         for(int j=1;j<=w;j++)
71             printf("%d ",s[i][j]);
72         printf("\n");
73     }
74     return 0;
75 }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-08-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i
Angel_Kitty
2018/04/09
8230
Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】
B. New Job time limit per test:1 second memory limit per test:64 megabytes input:standard input output:standard output This is the first day for you at your new job and your boss asks you to copy some files from one computer to other computers in an inform
Angel_Kitty
2018/04/09
5520
Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+
F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standard input output:standard output Ahmad is one of the best students in HIAST, and also a very good problems Solver. In the time you will spend reading this pro
Angel_Kitty
2018/04/09
1.1K0
Codeforces Beta Round #72 (Div. 1 Only)B. Doctor
There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore knows exactly that the animal number i in the queue will have to visit his office exactly ai times. We will assume that an examination takes much more time than making tests and other extra procedures, and therefore we will assume that once an animal leaves the room, it immediately gets to the end of the queue to the doctor. Of course, if the animal has visited the doctor as many times as necessary, then it doesn't have to stand at the end of the queue and it immediately goes home.
glm233
2020/09/28
3420
BZOJ 2257: [Jsoi2009]瓶子和燃料【数论:裴蜀定理】
2257: [Jsoi2009]瓶子和燃料 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 1326  Solved: 815 Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了。 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子来换。jyy 的飞船上共有 N个瓶子(1<=N<=1000) ,经过协商,火星人只要其中的K 个 。 jyy 将 K个瓶子交给火星人之后,火星人用它们装一些燃料给 jyy。所有的瓶
Angel_Kitty
2018/04/09
6060
Gym 100952A&&2015 HIAST Collegiate Programming Contest A. Who is the winner?【字符串,暴力】
A. Who is the winner? time limit per test:1 second memory limit per test:64 megabytes input:standard
Angel_Kitty
2018/04/09
4910
Codeforces Round #559 (Div. 2)B. Expansion coefficient of the array
Let's call an array of non-negative integers a1,a2,…,ana1,a2,…,an a kk-extension for some non-negative integer kk if for all possible pairs of indices 1≤i,j≤n1≤i,j≤n the inequality k⋅|i−j|≤min(ai,aj)k⋅|i−j|≤min(ai,aj) is satisfied. The expansion coefficient of the array aa is the maximal integer kk such that the array aa is a kk-extension. Any array is a 0-expansion, so the expansion coefficient always exists.
glm233
2020/09/28
6050
BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MB Submit: 10374  Solved: 4535 [Submit][Status][Discuss] Description   现在请求你维护一个数列,要求提供以下两种操作:1、 查询操作。语法:Q L 功能:查询当前数列中末尾L 个数中的最大的数,并输出这个数的值。限制:L不超过当前数列的长度。2、 插入操作。语法:A n 功能:将n加 上t,其中t是最近一
Angel_Kitty
2018/04/09
6050
Gym 100952D&&2015 HIAST Collegiate Programming Contest D. Time to go back【杨辉三角预处理,组合数,dp】
D. Time to go back time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output You have been out of Syria for a long time, and you recently decided to come back. You remember that you have M friends there an
Angel_Kitty
2018/04/09
5350
AtCoder Regular Contest 069 D
D - Menagerie ---- Time limit : 2sec / Memory limit : 256MB Score : 500 points Problem Statement Snuke, who loves animals, built a zoo. There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle. The animal number
Angel_Kitty
2018/04/08
9480
AtCoder Regular Contest 069 D
Codeforces 626D Jerry's Protest(暴力枚举+概率)
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and
Angel_Kitty
2018/04/09
6510
Codeforces 626D Jerry's Protest(暴力枚举+概率)
UESTC 30 &&HDU 2544最短路【Floyd求解裸题】
最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 65817    Accepted Submission(s): 28794 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的
Angel_Kitty
2018/04/09
6410
BZOJ 1303: [CQOI2009]中位数图【前缀和】
1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MB Submit: 2737  Solved: 1698 [Submit][Status][Discuss] Description 给出1~n的一个排列,统计该排列有多少个长度为奇数的连续子序列的中位数是b。中位数是指把所有元素从小到大排列后,位于中间的数。 Input 第一行为两个正整数n和b ,第二行为1~n 的排列。 Output 输出一个整数,即中位数为b的连续子序列个数。 S
Angel_Kitty
2018/04/09
8980
POJ 3662 Telephone Lines【Dijkstra最短路+二分求解】
Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7214 Accepted: 2638 Description Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for som
Angel_Kitty
2018/04/09
7770
Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】
C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standard input output:standard output Given string with N characters, your task is to transform it to a palindrome string. It's not as easy as you may think becaus
Angel_Kitty
2018/04/09
6670
HDU 2689 Sort it【树状数组】
Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4672    Accepted Submission(s): 3244 Problem Description You want to processe a sequence of n distinct integers by swapping two adjacent se
Angel_Kitty
2018/04/09
8770
Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard input output:standard output Syrian Collegiate Programming Contest (SCPC) is the qualified round for the Arab Collegiate Programming Contest. Each year SCPC or
Angel_Kitty
2018/04/09
5770
Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
POJ 1163 The Triangle【dp+杨辉三角加强版(递归)】
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 49955 Accepted: 30177 Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the hi
Angel_Kitty
2018/04/09
4780
洛谷 2634&&BZOJ 2152: 聪聪可可【点分治学习+超详细注释】
2152: 聪聪可可 Time Limit: 3 Sec  Memory Limit: 259 MB Submit: 3435  Solved: 1776 [Submit][Status][Discuss] Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃、两个人都想玩儿电脑(可是他们家只有一台电脑)……遇到这种问题,一般情况下石头剪刀布就好了,可是他们已经玩儿腻了这种低智商的游戏。他们的爸爸快被他们的争吵烦死了,所以他发明了一个新游戏:由爸爸
Angel_Kitty
2018/04/09
5410
Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】
G. The jar of divisors time limit per test:2 seconds memory limit per test:64 megabytes input:standard input output:standard output Alice and Bob play the following game. They choose a number N to play with. The rules are as follows: - They write each numb
Angel_Kitty
2018/04/09
5840
推荐阅读
Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
8230
Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】
5520
Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+
1.1K0
Codeforces Beta Round #72 (Div. 1 Only)B. Doctor
3420
BZOJ 2257: [Jsoi2009]瓶子和燃料【数论:裴蜀定理】
6060
Gym 100952A&&2015 HIAST Collegiate Programming Contest A. Who is the winner?【字符串,暴力】
4910
Codeforces Round #559 (Div. 2)B. Expansion coefficient of the array
6050
BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】
6050
Gym 100952D&&2015 HIAST Collegiate Programming Contest D. Time to go back【杨辉三角预处理,组合数,dp】
5350
AtCoder Regular Contest 069 D
9480
Codeforces 626D Jerry's Protest(暴力枚举+概率)
6510
UESTC 30 &&HDU 2544最短路【Floyd求解裸题】
6410
BZOJ 1303: [CQOI2009]中位数图【前缀和】
8980
POJ 3662 Telephone Lines【Dijkstra最短路+二分求解】
7770
Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】
6670
HDU 2689 Sort it【树状数组】
8770
Gym 100952E&&2015 HIAST Collegiate Programming Contest E. Arrange Teams【DFS+剪枝】
5770
POJ 1163 The Triangle【dp+杨辉三角加强版(递归)】
4780
洛谷 2634&&BZOJ 2152: 聪聪可可【点分治学习+超详细注释】
5410
Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】
5840
相关推荐
Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文