AtCoder Beginner Contest 069【A,水,B,水,C,数学,D,暴力】
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:
n m
Output
Print the number of blocks in K-city.
Sample Input 1
Copy
3 4
Sample Output 1
Copy
6
There are six blocks, as shown below:
Sample Input 2
Copy
2 2
Sample Output 2
Copy
1
There are one block, as shown below:
题目链接:http://abc069.contest.atcoder.jp/tasks/abc069_a
分析:结论就是ans=(a-1)*(b-1)
下面给出AC代码:
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:
s
Output
Print the abbreviation of s.
Sample Input 1
Copy
internationalization
Sample Output 1
Copy
i18n
Sample Input 2
Copy
smiles
Sample Output 2
Copy
s4s
Sample Input 3
Copy
xyz
Sample Output 3
Copy
x1z
题目链接:http://abc069.contest.atcoder.jp/tasks/abc069_b
分析:输出第一个,最后一个就好咯
下面给出AC代码:
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≤i≤N−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:
N
a1 a2 … aN
Output
If Snuke can achieve his objective, print Yes
; otherwise, print No
.
Sample Input 1
Copy
3
1 10 100
Sample Output 1
Copy
Yes
One solution is (1,100,10).
Sample Input 2
Copy
4
1 2 3 4
Sample Output 2
Copy
No
It is impossible to permute a so that the condition is satisfied.
Sample Input 3
Copy
3
1 4 1
Sample Output 3
Copy
Yes
The condition is already satisfied initially.
Sample Input 4
Copy
2
1 1
Sample Output 4
Copy
No
Sample Input 5
Copy
6
2 7 1 8 2 8
Sample Output 5
Copy
Yes
题目链接:http://abc069.contest.atcoder.jp/tasks/arc080_a
分析:统计4的倍数,2的倍数还有不是这两个的倍数的数,然后2个2的倍数等于4的倍数,然后就这样了!
下面给出AC代码:
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≤i≤N), there are exactly ai squares painted in Color i. Here, a1+a2+…+aN=HW.
- For each i (1≤i≤N), 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≤N≤HW
- ai≥1
- a1+a2+…+aN=HW
Input
Input is given from Standard Input in the following format:
H W
N
a1 a2 … aN
Output
Print one way to paint the squares that satisfies the conditions. Output in the following format:
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
2 2
3
2 1 1
Sample Output 1
Copy
1 1
2 3
Below is an example of an invalid solution:
1 2
3 1
This is because the squares painted in Color 1 are not 4-connected.
Sample Input 2
Copy
3 5
5
1 2 3 4 5
Sample Output 2
Copy
1 4 4 4 3
2 5 4 5 3
2 5 5 5 3
Sample Input 3
Copy
1 1
1
1
Sample Output 3
Copy
1
题目链接:http://abc069.contest.atcoder.jp/tasks/arc080_b
分析:从一个点可以到达其它所有的点,直接来一个水平填充好像就过了
下面给出AC代码:
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 }
- python基础知识——函数
- tensorflow之tf.placeholder 与 tf.Variable区别对比
- 11g备库搭建碰到自己给自己埋的坑(r7笔记第63天)
- JDBC基础入门(2)
- 11g备库无法开启ADG的原因分析 (r7笔记第62天)
- JDBC基础入门(3)
- Python多元线性回归-sklearn.linear_model,并对其预测结果评估
- python 聚类分析实战案例:K-means算法(原理源码)
- JAVA面试题解惑——final、finally和finalize的区别
- Java内存管理
- python基础知识——内置数据结构(字典)
- mysql、mongodb、python(dataframe).聚合函数的形式,以及报错解决方案
- JavaScript计算水仙花数【可自定义范围】
- JSP简单入门(1)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Redis 发布订阅,小功能大用处,真没那么废材!
- R语言实现生物序列的降维比对
- Tomcat NIO(9)-IO线程-Overall流程和关键类
- 有限元平面四边形等差单元python编程
- 动图演示:手撸堆栈的两种实现方法!
- [Go] 实战项目在线客服GO-FLY -在gin框架使用IP识别库转换IP为城市
- leetcode1552题解【二分+贪心】
- 这三年被分布式坑惨了,曝光十大坑
- 为什么删数据也提示空间不足呢?
- 前端踩坑系列《六》——让人又爱又恨的npm包
- docker运行Tomcat后访问首页报404(详细永久解决步骤)
- vue.js如何快速入门第1篇
- 3.列表-HTML基础
- 启动时间的一些分析
- 1.HTML基础知识-HTML进阶