码迷,mamicode.com
首页 > 其他好文 > 详细

HZNU 2019 Summer training 8

时间:2019-07-12 20:08:00      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:cin   summer   cto   class   ring   alt   for   sed   ica   

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;
}
View Code

 

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;

    }


}
View Code

 

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);
    }
}
View Code

 

D - Olya and magical square

 CodeForces - 1080D 
 

E - Sonya and Matrix Beauty

 CodeForces - 1080E 
 

HZNU 2019 Summer training 8

标签:cin   summer   cto   class   ring   alt   for   sed   ica   

原文地址:https://www.cnblogs.com/smallhester/p/11178090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!