A - Petya and Origami
CodeForces - 1080A
题意:制造一份邀请函需要2份a物品,5份b物品,8份c物品,一个盒子里面有k份物品(可以为a或b或c)问你制造n份邀请函需要用多少个盒子
题解:加起来就行了
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include<stack>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;
const int maxn = 4e4 + 10;
const int mod = 1e9 + 7;
int main()
{
int n,k;
cin >> n >> k;
int sum = 0;
sum += ceil(2.0 * n / (k * 1.0));
sum += ceil(5.0 * n / (k * 1.0));
sum += ceil(8.0 * n / (k * 1.0));
cout << sum << endl;
}
B - Margarite and the best present
CodeForces - 1080B
题意:区间内偶数和减去奇数和
题解:分类一下就好了
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include<stack>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;
const int maxn = 4e4 + 10;
const int mod = 1e9 + 7;
int main()
{
int t;
cin >> t;
while (t--)
{
ll l, r;
cin >> l >> r;
ll ans;
if (l == r)
{
if (l % 2 == 0)
ans = l;
else
ans = -1 * l;
}
else
{
if (l % 2 == 1 && r % 2 == 1)
ans = (r - l) / 2 - r;
else if (l % 2 == 1 && r % 2 == 0)
ans = (r - l + 1) / 2;
else if (l % 2 == 0 && r % 2 == 0)
ans = -1*(r - l) / 2 + r;
else
ans = ((r - l + 1) / 2) * (-1);
}
cout << ans << endl;
}
}
C - Masha and two friends
CodeForces - 1080C
题意:给你一个n行m列的黑白块相间的棋盘,进行两次操作,第一次把(x1,y1)到(x2,y2)的区域全部涂白,第二次把(x3,y3)到(x4,y4)的区域全部涂黑,问你这样以后黑白各有多少块?
题解:分割矩形,判断矩形的左下角的点是黑色还是白色就好了
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include<stack>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long LL;
const int maxn = 4e4 + 10;
const int mod = 1e9 + 7;
LL n,m,black,white;
int X1,X2,X3,X4,Y1,Y2,Y3,Y4;
void jishu(LL lx,LL ly,LL rx,LL ry,bool flag) {
LL N = ry - ly + 1, M = rx - lx + 1, b, w;
LL tmp = N * M / 2;
LL res = N * M - tmp;
if((lx + ly) % 2) {
w = tmp;
b = res;
}
else {
b = tmp;
w = res;
}
if(flag) {
white += b;
black -= b;
}
else {
black += w;
white -= w;
}
}
void cut(LL x1,LL y1,LL x2,LL y2)
{
if(x1 > x2 || y1 > y2)
return;
if(x2<X3 || y2<Y3 || x1>X4 || y1>Y4)
{
jishu(x1,y1,x2,y2,1);
return;
}
if(x1<X3) {
cut(x1, y1, X3 - 1, y2);
x1 = X3;
}
if(x2>X4) {
cut(X4 + 1, y1, x2, y2);
x2 = X4;
}
if(y1<Y3) {
cut(x1, y1, x2, Y3 - 1);
y1 = Y3;
}
if(y2>Y4) {
cut(x1, Y4 + 1, x2, y2);
y2 = Y4;
}
}
int main()
{
int t;
cin >> t;
while(t--)
{
cin >> n >> m;
cin >> X1 >> Y1 >> X2 >> Y2;
cin >> X3 >> Y3 >> X4 >> Y4;
black = n * m / 2;
white = n * m - black;
cut(X1,Y1,X2,Y2);
jishu(X3,Y3,X4,Y4,0);
printf("%lld %lld\n",white,black);
}
}
D - Olya and magical square
CodeForces - 1080D
题意:有一个初始时宽为 2
n的正方形,你每次可以对一个完整的正方形进行四等分。问是否存在一种方案,使得在恰好四等分 k次之后,存在一条等宽的路径,使得左下角的方块和右上角的方块联通(四联通),如果这种方案存在,输出路径的宽度对2取对数的值。
题解:n大于31的话,只需要切右下角的一块就可以了,那么答案就是n -1,n小于等于31的时候枚举答案即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string.h>
#include<cstring>
using namespace std;
#define LL long long
const int MAXN = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
LL tot[40];
int main()
{
LL n,k,t;
LL cur = 1;
for(int i = 0; i <= 31; i++,cur *= 4)
{
tot[i] = (cur - 1) / 3;
}
cin >> t;
while(t--)
{
cin >> n >> k;
if (n > 31)
printf("YES %lld\n", n - 1);
else
{
int ans = -1;
for(int i = 0; i < n; i++)
{
LL tmp = n - i,need = (1LL << tmp + 1) - tmp - 2;
if(need <= k)
{
LL last = tot[n] - ((1LL << tmp + 1) - 1) * tot[i];
if(last >= k)
{
ans = i;
break;
}
}
}
if(~ans)
printf("YES %d\n",ans);
else
puts("NO");
}
}
}