AtCoder Beginner Contest 069 ABCD题
题目链接:http://abc069.contest.atcoder.jp/assignments
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
3 4
Sample Output 1
6
There are six blocks, as shown below:
Sample Input 2
2 2
Sample Output 2
1
There are one block, as shown below:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main()
{
int n,m;
while(cin>>n>>m){
cout<<(n-)*(m-)<<endl;
}
return ;
}
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
internationalization
Sample Output 1
i18n
Sample Input 2
smiles
Sample Output 2
s4s
Sample Input 3
xyz
Sample Output 3
x1z
题解:水题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main()
{
string a;
while(cin>>a){
int len=a.length();
cout<<a[]<<len-<<a[len-]<<endl;
}
return ;
}
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
3
1 10 100
Sample Output 1
Yes
One solution is (1,100,10).
Sample Input 2
4
1 2 3 4
Sample Output 2
No
It is impossible to permute a so that the condition is satisfied.
Sample Input 3
3
1 4 1
Sample Output 3
Yes
The condition is already satisfied initially.
Sample Input 4
2
1 1
Sample Output 4
No
Sample Input 5
6
2 7 1 8 2 8
Sample Output 5
Yes
题解:找出4和2的倍数即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int N=;
int a[N];
int main()
{
int n;
cin>>n;
int t1=,t2=;
for(int i=;i<n;i++){
cin>>a[i];
if(a[i]%==)
t1++;
else if(a[i]%==)
t2++;
}
int flag=;
int m;
if(t2%==) m=t2;
else m=t2-;
if((n-m)/<=t1)flag=;
if(flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return ;
}
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 iby 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
2 2
3
2 1 1
Sample Output 1
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
3 5
5
1 2 3 4 5
Sample Output 2
1 4 4 4 3
2 5 4 5 3
2 5 5 5 3
Sample Input 3
1 1
1
1
Sample Output 3
1
题解:看半天不懂撒意思 题解说是蛇形填数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int r,c,n,x,y,ans[][];
int main(void)
{
scanf("%d%d%d",&r,&c,&n);
x=,y=;
for(int i=,cnt;i<=n;i++){
scanf("%d",&cnt);
while(cnt--){
ans[x][y]=i;
if(y==c&&x%==)
y=c,x++;
else if(y==&&x%==)
y=,x++;
else if(x&)
y++;
else
y--;
}
}
for(int i=;i<=r;i++)
for(int j=;j<=c;j++)
printf("%d%c",ans[i][j],j==c?'\n':' ');
return ;
}
AtCoder Beginner Contest 069 ABCD题的更多相关文章
- AtCoder Beginner Contest 068 ABCD题
A - ABCxxx Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement This contes ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 070 ABCD题
题目链接:http://abc070.contest.atcoder.jp/assignments A - Palindromic Number Time limit : 2sec / Memory ...
- AtCoder Beginner Contest 057 ABCD题
A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...
- AtCoder Beginner Contest 051 ABCD题
A - Haiku Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement As a New Yea ...
- AtCoder Beginner Contest 052 ABCD题
A - Two Rectangles Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement The ...
- AtCoder Beginner Contest 054 ABCD题
A - One Card Poker Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Ali ...
- AtCoder Beginner Contest 058 ABCD题
A - ι⊥l Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Three poles st ...
- AtCoder Beginner Contest 050 ABC题
A - Addition and Subtraction Easy Time limit : 2sec / Memory limit : 256MB Score : 100 points Proble ...
随机推荐
- fatal error: vector: No such file or directory
jni/mac.cpp:28:18: fatal error: vector: No such file or directory jni/mac.cpp:29:18: fatal error: me ...
- uWSGI+APScheduler不能执行定时任务
在本地项目中使用APScheduler运行定时任务ok,但是在服务器上用uwsgi部署的Django环境下,APScheduler定时任务并不会被启动. 原因:uwsgi 默认one thread o ...
- Pycharm快捷键大全(windows + Mac)
Windows快捷键 1.编辑 Ctrl + Space 基本的代码完成(类.方法.属性) Ctrl + Alt + Space 快速导入任意类 Ctrl + Shift + Enter ...
- what's the 单例模式
what's the 单例模式 单例模式,是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例的特殊类.通过单例模式可以保证系统中,应用该模式的类一个类只有一个实例.即一个类只有一个对象实例 ...
- SQL Server Management Studio最新版下载地址
https://docs.microsoft.com/zh-cn/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server ...
- IE无法安装Activex控件
由于无法验证发行者,所以windows已经阻止此软件,如要安装未签名的activex控件,按如下步骤: 1.打开Internet Explorer---菜单栏点“工具”---Internet选项--安 ...
- Mongodb 基础 查询表达式
数据库操作 查看:show dbs; 创建:use dbname; // db.createCollection('collection_name'); 隐式创建,需要创建的数据库中有表才表示创 ...
- 最短路径-并查集+Floyd[转载]
题目描述 N个城市,标号从0到N-1,M条道路,第K条道路(K从0开始)的长度为2^K,求编号为0的城市到其他城市的最短距离 输入描述: 第一行两个正整数N(2<=N<=100)M(M&l ...
- Laravel传值总结
Laravel传值:with,view(),compact方法一:with public function index() { $title = '文章标题1'; return view('artic ...
- PHP的数组合并
1. array_merge 字符索引:后面的覆盖前面的. 如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值. 混合索引:如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到 ...