AtCoder Beginner Contest 069【A,水,B,水,C,数学,D,暴力】
2017-08-06 23:00
525 查看
A - K-City
Time limit : 2sec / Memory limit : 256MBScore : 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≤100Input
Input is given from Standard Input in the following format:n m
Output
Print the number of blocks in K-city.Sample Input 1
Copy3 4
Sample Output 1
Copy6
There are six blocks, as shown below:
Sample Input 2
Copy2 2
Sample Output 2
Copy1
There are one block, as shown below:
题目链接:http://abc069.contest.atcoder.jp/tasks/abc069_a
分析:结论就是ans=(a-1)*(b-1)
下面给出AC代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } inline void write(int x) { if(x<0) { putchar('-'); x=-x; } if(x>9) { write(x/10); } putchar(x%10+'0'); } int main() { int a,b; cin>>a>>b; cout<<(a-1)*(b-1)<<endl; return 0; }
B - i18n
Time limit : 2sec / Memory limit : 256MBScore : 200 points
Problem Statement
The wordinternationalizationis sometimes abbreviated to
i18n. This comes from the fact that there are 18 letters between the first
iand 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
Copyinternationalization
Sample Output 1
Copyi18n
Sample Input 2
Copysmiles
Sample Output 2
Copys4s
Sample Input 3
Copyxyz
Sample Output 3
Copyx1z
题目链接:http://abc069.contest.atcoder.jp/tasks/abc069_b
分析:输出第一个,最后一个就好咯
下面给出AC代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } inline void write(int x) { if(x<0) { putchar('-'); x=-x; } if(x>9) { write(x/10); } putchar(x%10+'0'); } char s[105]; int main() { cin>>s; int len=strlen(s); cout<<s[0]<<len-2<<s[len-1]<<endl; return 0; }
C - 4-adjacent
Time limit : 2sec / Memory limit : 256MBScore : 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≤105ai 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, printYes; otherwise, print
No.
Sample Input 1
Copy3 1 10 100
Sample Output 1
CopyYes
One solution is (1,100,10).
Sample Input 2
Copy4
1 2 3 4
Sample Output 2
CopyNo
It is impossible to permute a so that the condition is satisfied.
Sample Input 3
Copy3
1 4 1
Sample Output 3
CopyYes
The condition is already satisfied initially.
Sample Input 4
Copy2
1 1
Sample Output 4
CopyNo
Sample Input 5
Copy62 7 1 8 2 8
Sample Output 5
CopyYes
题目链接:http://abc069.contest.atcoder.jp/tasks/arc080_a
分析:统计4的倍数,2的倍数还有不是这两个的倍数的数,然后2个2的倍数等于4的倍数,然后就这样了!
下面给出AC代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } inline void write(int x) { if(x<0) { putchar('-'); x=-x; } if(x>9) { write(x/10); } putchar(x%10+'0'); } int main() { int n; cin>>n; int a=0,b=0,c=0; for(int i=0;i<n;i++) { ll x; x=read(); if(x%4==0) a++; else if(x%2==0) b++; else c++; } if(b>0) c++; if(a+1>=c) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
D - Grid Coloring
Time limit : 2sec / Memory limit : 256MBScore : 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≤1001≤N≤HW
ai≥1a1+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
Copy2 23
2 1 1
Sample Output 1
Copy1 12 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
Copy3 5 5 1 2 3 4 5
Sample Output 2
Copy1 4 4 4 3 2 5 4 5 3 2 5 5 5 3
Sample Input 3
Copy1 111
Sample Output 3
Copy1
题目链接:http://abc069.contest.atcoder.jp/tasks/arc080_b
分析:从一个点可以到达其它所有的点,直接来一个水平填充好像就过了
下面给出AC代码:
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } inline void write(int x) { if(x<0) { putchar('-'); x=-x; } if(x>9) { write(x/10); } putchar(x%10+'0'); } int w,h,n; int s[105][105]; int cnt[10005]; int main() { h=read(); w=read(); n=read(); for(int i=1;i<=n;i++) cnt[i]=read(); int k=1; for(int i=1;i<=h;i++) { if(i%2==1) { for(int j=1;j<=w;j++) { if(cnt[k]==0) k++; cnt[k]--; s[i][j]=k; } } else { for(int j=w;j>0;j--) { if(cnt[k]==0) k++; cnt[k]--; s[i][j]=k; } } } for(int i=1;i<=h;i++) { for(int j=1;j<=w;j++) printf("%d ",s[i][j]); printf("\n"); } return 0; }
相关文章推荐
- AtCoder Beginner Contest 069 ABC C++&&Python
- AtCoder Beginner Contest 069
- AtCoder Beginner Contest 069
- AtCoder Beginner Contest 080 C - Shopping Street【暴力枚举】
- AtCoder Beginner Contest 069 C - 4-adjacen
- AtCoder Beginner Contest 085 C - Otoshidama【暴力】
- AtCoder Beginner Contest 069 D - Grid Coloring
- AtCoder Beginner Contest 085 C Otoshidama(计算机整数乘法问题+方程求解)
- AtCoder Beginner Contest 084
- AtCoder Beginner Contest 087 D题
- AtCoder Beginner Contest 088 C Takahashi's Information 【思维枚举】
- AtCoder Beginner Contest 086 C - Traveling
- AtCoder Beginner Contest 089 D - Practical Skill Test 边界处理
- AtCoder Beginner Contest 091 D - Two Sequences
- AtCoder Beginner Contest 084 C - Special Trains(思路)
- AtCoder Beginner Contest 084 D - 2017-like Number (区间问题 a[r]-a[l-1])
- AtCoder Beginner Contest 085 C Otoshidama(计算机整数乘法问题+方程求解)
- AtCoder Beginner Contest 089 D - Practical Skill Test 边界处理
- AtCoder Beginner Contest 073
- AtCoder Beginner Contest 091 C - 2D Plane 2N Points