AtCoder Beginner Contest 069 ABC C++&&Python

A - K-City


Time limit : 2sec /Memory limit : 256MB

Score : 100 points

Problem Statement

In K-city, there are n streets running east-west, andm 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

  • 2n,m100

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:

9179be829dc9810539213537d4c7398c.png

Sample Input 2

Copy
2 2

Sample Output 2

Copy
1

There are one block, as shown below:

997bfafa99be630b54d037225a5c68ea.png

水题。

问你n条横线与m条竖线垂直相交能得出多少个小矩形

隐隐约约记得小学写过.......

python:

a,b=map(int,input().split())
print((a-1)*(b-1))
C++:

#include<iostream>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1)<<endl;
}


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 are18 letters between the firsti and the last n.

You are given a string s of length at least3 consisting of lowercase English letters.Abbreviates in the same way.

Constraints

  • 3|s|100 (|s| denotes the length ofs.)
  • 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
水题......

给你一个单词,输出它的首字母和首字母到最后的字母间有多少个字母,再输出最后的字母

python:

s=input()
print(s[:1]+str(len(s[1:len(s)-1]))+s[-1:])
C++:

#include<iostream>
#include<cstring>
using namespace std;
int main(){
	char str[110];
	scanf("%s",str);
	cout<<str[0]<<strlen(str)-2<<str[strlen(str)-1]<<endl;
}

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).Eachai is a positive integer.

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

  • For each 1iN1, the product of ai andai+1 is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

  • 2N105
  • ai is an integer.
  • 1ai109

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

题意是给你一段序列,能否通过交换他们的位置使它满足前一个乘后一个的积为4的倍数

满足:总数的一半<=被4整除数的个数或者是被4整除数的个数*2+被2整除但不能被4整除数的个数 <= 总数。

找出4和2的倍数

python:

n=int(input())
a=list(map(int,input().split()))
num_O=sum(map(lambda x:1 if not x%2 else 0,a))
num_T=sum(map(lambda x:1 if not x%4 else 0,a))
if(n//2-num_T-(num_O-num_T)//2<=0):
	print("Yes")
else:
	print("No")

C++:

#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int flag=0;
	int flag1=0;
	int i=n;
	while(i--){
		int a;
		cin>>a;
		if(a%4==0) flag++;
		else if(a%2==0) flag1++;
	}
	int flag2=0;
	int tmp;
	if(flag1%2==0) tmp=flag1;
	else tmp=flag1-1;
	if((n-tmp)/2<=flag) flag2=1;
	if(flag2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值