签到四题~~~
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} Ccnt11种。
那么总方案个数就是 C c n t 1 1 × 2 c n t 0 C_{cnt_1}^{1} \times 2^{cnt_0} Ccnt11×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
关注
打赏
- 回坑记之或许是退役赛季?
- [LCT刷题] P1501 [国家集训队]Tree II
- [LCT刷题] P2147 洞穴勘测
- 2022-2023 ICPC Brazil Subregional Programming Contest VP记录
- [线段树套单调栈] 2019-2020 ICPC Asia Hong Kong Regional Contest H.[Hold the Line]
- The 2021 ICPC Asia Nanjing Regional Contest E.Paimon Segment Tree 区间合并线段树/维护矩阵乘法
- CF580E - Kefa and Watch 线段树维护哈希
- HDU5869 Different GCD Subarray Query 离线查询/区间贡献
- 27.CF1004F Sonya and Bitwise OR 区间合并线段树
- 26.CF1000F One Occurrence