A - Magical Sticks CodeForces - 1371A
A penguin Rocher has n sticks. He has exactly one stick with length i for all 1≤i≤n.
He can connect some sticks. If he connects two sticks that have lengths a and b, he gets one stick with length a+b. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his set and can be used for the next connections.
He wants to create the maximum number of sticks that have the same length. It is not necessary to make all sticks have the same length, some sticks can have the other length. How many sticks with the equal length he can create?
Input
The input consists of multiple test cases. The first line contains a single integer t (1≤t≤1000) — the number of test cases. Next t lines contain descriptions of test cases.
For each test case, the only line contains a single integer n (1≤n≤109).
Output
For each test case, print a single integer — the answer to the problem.
Input
4
1
2
3
4
Output
1
1
2
2
题意思路: 要1到n的棒子两个组成一个,求相同长度的棒子的数目 偶数的话首位相加 技术的话去掉最后一个首位相加
代码:
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<string>
#define LL long long
using namespace std;
#define MAXN 1011
#define inf 100000001
#define sd1(i) scanf("%d", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
int T;
int N;
int a;
int main(){
sd1(T);
while(T--){
int ans = 0;
sd1(a);
if(a <= 2) {
cout << 1 << endl;
continue;
}
if(a == 3){
cout << 2 << endl;
continue;
}
if(a % 2 != 0) ans = a / 2 + 1;
else ans = a / 2;
cout << ans << endl;
}
}
B - Magical Calendar CodeForces - 1371B
题意 : 将n个方块放到一行1到r个的表格中 有几种方法 条件 : 1 .如图形状相同的不算 ;2.每个方块必须上下或左右相连
思路: 可以观察出 当方块数大于当前一行的格子数n,有n种放法 大于等于是则只有一种
代码 :
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<string>
#define LL long long
using namespace std;
#define MAXN 1011
#define inf 100000001
#define sd1(i) scanf("%d", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
int T;
int N;
LL n, r;
int main(){
sd1(T);
LL ans = 0;
while(T--){
ans = 0;
sd2(n, r);
if(r == 1 || n == 1){
ans = 1;
}
else{
if(n > r){
ans = r * (r+1) / 2;
}
else {
LL nn = n - 1;
ans += nn * (nn + 1) / 2;
ans ++;
}
}
cout << ans << endl;
}
//system("pause");
}
C - A Cookie for You CodeForces - 1371C
题意 : 有两种蛋糕数目a, b 有两组人数目n, m。第一组那多的,第二组那少的 问最后是否会出现有人没蛋糕那的尴尬
思路: 刚开始的时候想的是先拿蛋糕的插差值使蛋糕数目相等,但后来考虑的情况太多了 wa了好激发 赛后想到:先判断一下人数和蛋糕的对应关系,然后比较下拿少的组的人数与蛋糕最少的数目即可 啊这
代码:
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<stdlib.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<stdio.h>
#include<string>
#define LL long long
using namespace std;
#define MAXN 1011
#define inf 100000001
#define sd1(i) scanf("%d", &i)
#define sd2(i, j) scanf("%d%d", &i, &j)
#define sl2(i, j) scanf("%lld%lld", &i, &j)
#define sd3(i, j, k) scanf("%d%d%d", &i, &j, &k)
int T;
LL a, b, m, n;
int main(){
sd1(T);
while(T--){
sd3(a, b, n);
sd1(m);
if(a+b < n+m){
cout << "NO" << endl;
continue;
}
LL c = min(a, b);
if(c < m) cout << "NO" << endl;
else cout << "YES" << endl;
}
//system("pause");
return 0;
}