CodeForce刷题表

Day12

1582A - Luntik and Concerts

题意:

有a首1分钟的歌,b首2分钟的歌,c首3分钟给的歌,有两场演出,任意分配这几首歌每首歌只能用一次,两场演出时间相差最小是多少?

思路:

枚举所有情况,按照奇、偶来判断6种情况。

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
const ll mod = 1e9+7;
int main(){
int _;cin>>_;
while(_--) {
int a,b,c;
cin>>a>>b>>c;
a = a%2, b = b%2, c = c%2;
if(a+b+c==0||a+b+c==3) //全奇、全偶
cout<<0<<endl;
else if(a+b+c==1) {//1奇2偶
if(a==1)
cout<<1<<endl;
else if(b==1)
cout<<0<<endl;
else if(c==1)
cout<<1<<endl;
}
else {//2奇1偶
if(a==0 ||c==0)
cout<<1<<endl;
else
cout<<0<<endl;
}
}
return 0;
}

总结:

我是这么写的,但是尼玛的看完官方题解我直接麻了。直接(a+c)%2就是答案=。=

1582B - Luntik and Subsequences

题意:

输入n个数,和为s,可以任意删除,有几种情况和变为s-1?

思路:

删掉一个1,任意个0。

也就是1的个数 × 2^0的个数次方

特别注意一点范围是long long

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
const ll mod = 1e9+7;
ll a[100];
int main(){
int _;cin>>_;
while(_--) {
ll n;
ll zero=0,one=0;
cin>>n;
for(int i=1;i<=n;i++) {
cin>>a[i];
if(a[i]==0)
zero++;
else if(a[i]==1)
one++;
}
ll res = ((ll)1<<zero);
cout<<res*one<<endl;
}
return 0;
}

总结:

位运算<<左移,要把1给变成long long。