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
- 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:

水题。
问你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
internationalization
Sample Output 1
i18n
Sample Input 2
smiles
Sample Output 2
s4s
Sample Input 3
xyz
Sample Output 3
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 1≤i≤N−1, the product of ai andai+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的倍数
满足:总数的一半<=被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;
}