您当前的位置: 首页 > 

HeartFireY

暂无认证

  • 2浏览

    0关注

    334博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Codeforces Round #750 (Div. 2) A.B.C.D

HeartFireY 发布时间:2021-10-28 01:03:38 ,浏览量:2

签到四题~~~

A.Luntik and Concerts

题目大意:给定三个整数 a , b , c a,b,c a,b,c,分别表示现在拥有的数字 1 , 2 , 3 1,2,3 1,2,3的个数,至少拥有一个。要求将这堆数字分成两部分,求两部分差值的最小值。

思路分析:首先我们需要明确:由于三个数字至少有一个。那么这些数字一定能够组成 [ 1 , s u m ] [1, sum] [1,sum]之间的全部数字。由于要使插值最小,那么我们需要让两个部分的和尽可能地接近。显然对于 s u m sum sum为偶数的情况下,一定可以组成 s u m 2 \frac {sum}{2} 2sum​,此时差值为 0 0 0;对于 s u m sum sum为奇数的情况下,同理可知最小差值为 1 1 1。

#include 
#define int long long
using namespace std;

inline void solve(){
    int a, b, c; cin >> a >> b >> c;
    int sum = a + b * 2 + c * 3;
    if(sum % 2) puts("1");
    else puts("0"); 
}

signed main(){
    int t = 0; cin >> t;
    while(t--) solve();
}
B.Luntik and Subsequences

题目分析:给定一个序列,设序列和为 s u m sum sum,要求找出等于 s u m − 1 sum - 1 sum−1子序列个数。

思路分析:我们不从子序列的构造方式考虑,而是从总序列删除元素的角度去考虑:设现在序列中有 c n t 0 cnt_0 cnt0​个 0 0 0, c n t 1 cnt_1 cnt1​个 1 1 1。

  • 删除 0 0 0,对序列和无影响,因此 0 0 0任意删,方案总共 2 c n t 0 2^{cnt_0} 2cnt0​种;
  • 删除 1 1 1,每次必须删一个且最多删除一个,方案总共 C c n t 1 1 C_{cnt_1}^{1} Ccnt1​1​种。

那么总方案个数就是 C c n t 1 1 × 2 c n t 0 C_{cnt_1}^{1} \times 2^{cnt_0} Ccnt1​1​×2cnt0​种。

#include 
#define int long long
using namespace std;
 
inline void solve(){
    int n = 0, cnt0 = 0, cnt1 = 0; cin >> n;
    for(int i = 1; i > num;
        if(num == 1) cnt1++;
        else if(num == 0) cnt0++;
    }
    int ans = cnt1 * (1ll  a[i];
    if(n & 1){
        if(a[1] + a[2] != 0) cout             
关注
打赏
1662600635
查看更多评论
0.0367s