9-25训练赛

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值