题目链接:A题
题目大意:问有多少个小于 2n 的形式是 2k−1 的能整除7的数字的个数
题目思路:7的二进制是111,而 2k−1 的二进制是k个1,所以只需要k能被3整除就好了
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
int T,n,m;
int main(){
scanf("%d",&T);
for(int Case = 1;Case <= T;Case++){
scanf("%d",&n);
printf("Case #%d: %d\n",Case,n/3);
}
return 0;
}
题目链接:D题
题目大意:有n个蛋糕,每个蛋糕都有尺寸,现在问你能形成多少个蛋糕塔,要求:蛋糕塔的层数一定得是k,每一层只有能一个蛋糕,下一层的蛋糕得尺寸至少得是上一层得两倍
题目思路:二分蛋糕塔的个数,然后我们优先取最小的mid个,然后线性扫看能合成多少层,然后层数和k比较得二分check性
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll maxn = 1e6+10;
ll T,a[maxn],b[maxn],n,k;
bool check(ll mid){
if(mid == 0) return true;
memset(b,0,sizeof(b));
ll cnt = 0,now = 0;
for(ll i = 0;i < n;i++){
if(a[i] >= b[now]*2){
b[now] = a[i];
now++;
if(now == mid){
cnt++;
now = 0;
}
}
}
if(cnt >= k) return true;
return false;
}
int main(){
scanf("%lld",&T);
for(ll Case = 1;Case <= T;Case++){
scanf("%lld%lld",&n,&k);
for(ll i = 0;i < n;i++) scanf("%lld",&a[i]);
sort(a,a+n);
ll l = 0,r = 1e6+10;
ll mid = (l+r)/2,maxx = -1;
while(l <= r){
mid = (l+r)/2;
if(check(mid)){
maxx = max(maxx,mid);
l = mid+1;
}
else r = mid-1;
}
printf("Case #%lld: %lld\n",Case,maxx);
}
return 0;
}
题目链接:L题
题目大意:有四个队伍进行足球比赛,赢方得3分,败方不得分,平局双方各得一分,给出最后得分,问是否合法,或者是否有多种情况
题目思路:因为比赛就6场,直接dfs一下就好了
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
struct node{
int a,b,c,d;
}res[1005];
int cnt = 0;
void dfs(int now,int a,int b,int c,int d){
if(now == 1){
dfs(now+1,a+3,b,c,d);
dfs(now+1,a,b+3,c,d);
dfs(now+1,a+1,b+1,c,d);
}
else if(now == 2){
dfs(now+1,a+3,b,c,d);
dfs(now+1,a,b,c+3,d);
dfs(now+1,a+1,b,c+1,d);
}
else if(now == 3){
dfs(now+1,a+3,b,c,d);
dfs(now+1,a,b,c,d+3);
dfs(now+1,a+1,b,c,d+1);
}
else if(now == 4){
dfs(now+1,a,b+3,c,d);
dfs(now+1,a,b,c+3,d);
dfs(now+1,a,b+1,c+1,d);
}
else if(now == 5){
dfs(now+1,a,b,c,d+3);
dfs(now+1,a,b+3,c,d);
dfs(now+1,a,b+1,c,d+1);
}
else if(now == 6){
dfs(now+1,a,b,c,d+3);
dfs(now+1,a,b,c+3,d);
dfs(now+1,a,b,c+1,d+1);
}
else if(now == 7){
res[cnt].a = a;
res[cnt].b = b;
res[cnt].c = c;
res[cnt].d = d;
cnt++;
return ;
}
}
int main(){
int T,a,b,c,d;
scanf("%d",&T);
dfs(1,0,0,0,0);
for(int Case = 1;Case <= T;Case++){
scanf("%d%d%d%d",&a,&b,&c,&d);
int cot = 0;
for(int i = 0;i < cnt;i++){
if(res[i].a == a&&res[i].b == b&&res[i].c == c&&res[i].d == d) cot++;
}
if(cot == 0) printf("Case #%d: Wrong Scoreboard\n",Case);
else if(cot == 1) printf("Case #%d: Yes\n",Case);
else printf("Case #%d: No\n",Case);
}
return 0;
}