A. Petya and Origami
                        

time limit per test 

1 second

                  
 
                        memory limit per test 

256 megabytes

input

standard input

output

standard output

Petya is having a party soon, and he has decided to invite his nn friends.

He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one color with kk sheets. That is, each notebook contains kk sheets of either red, green, or blue.

Find the minimum number of notebooks that Petya needs to buy to invite all nn of his friends.

Input

The first line contains two integers nn and kk (1≤n,k≤1081≤n,k≤108) — the number of Petya's friends and the number of sheets in each notebook respectively.

Output

Print one number — the minimum number of notebooks that Petya needs to buy.

Examples
input
3 5
output
10
input
15 6
output
38

In the first example, we need 22 red notebooks, 33 green notebooks, and 55 blue notebooks.

In the second example, we need 55 red notebooks, 1313 green notebooks, and 2020 blue notebooks.

题解:水题;向上取证即可;

参考代码:

 #include<bits/stdc++.h>
using namespace std;
#define cls(x, val) memset(x,val,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
const int INf=0x3f3f3f3f;
double n,k,n1,n2,n3;
int main()
{
scanf("%lf%lf",&n,&k);
n1=*n,n2=*n,n3=*n;
int sum=ceil(n1/k)+ceil(n2/k)+ceil(n3/k);
printf("%d\n",sum); return ;
}
 
                        B. Margarite and the best present
time limit per test 

1 second

  
 
                        
 
                      
 
memory limit per test 

256 megabytes

input

standard input

output

standard output

Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.

Recently, she was presented with an array aa of the size of 109109 elements that is filled as follows:

  • a1=−1a1=−1
  • a2=2a2=2
  • a3=−3a3=−3
  • a4=4a4=4
  • a5=−5a5=−5
  • And so on ...

That is, the value of the ii-th element of the array aa is calculated using the formula ai=i⋅(−1)iai=i⋅(−1)i.

She immediately came up with qq queries on this array. Each query is described with two numbers: ll and rr. The answer to a query is the sum of all the elements of the array at positions from ll to rr inclusive.

Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.

Help her find the answers!

Input

The first line contains a single integer qq (1≤q≤1031≤q≤103) — the number of the queries.

Each of the next qq lines contains two integers ll and rr (1≤l≤r≤1091≤l≤r≤109) — the descriptions of the queries.

Output

Print qq lines, each containing one number — the answer to the query.

Example
input
5
1 3
2 5
5 5
4 4
2 3
output
-2
-2
-5
4
-1 In the first query, you need to find the sum of the elements of the array from position 11 to position 33. The sum is equal to a1+a2+a3=−1+2−3=−2a1+a2+a3=−1+2−3=−2.

In the second query, you need to find the sum of the elements of the array from position 22 to position 55. The sum is equal to a2+a3+a4+a5=2−3+4−5=−2a2+a3+a4+a5=2−3+4−5=−2.

In the third query, you need to find the sum of the elements of the array from position 55 to position 55. The sum is equal to a5=−5a5=−5.

In the fourth query, you need to find the sum of the elements of the array from position 44 to position 44. The sum is equal to a4=4a4=4.

In the fifth query, you need to find the sum of the elements of the array from position 22 to position 33. The sum is equal to a2+a3=2−3=−1a2+a3=2−3=−1.

题解:水题,就是求数组的区间和,数组:奇数为负,偶数为正;先判断是奇数开头还是偶数开头,然后除2*1(奇数*-1),然后判断(r-l+1)是奇数还是偶数,然后最后一个元素特判即可;

参考代码:

 #include<bits/stdc++.h>
using namespace std;
#define cls(x, val) memset(x,val,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
const int INf=0x3f3f3f3f;
int n,l,r;
int main()
{
scanf("%d",&n);
while(n--)
{
int sum;
scanf("%d%d",&l,&r);
if(l%)
{
int num=(r-l+)/,temp=(r-l+)%;
sum=num+temp*(-r);
}
else
{
int num=(r-l+)/,temp=(r-l+)%;
sum=-num+temp*r;
}
printf("%d\n",sum);
} return ;
}
 
C. Masha and two friends

                                      
 
                         
 
time limit pertest 

1 second

        
 
                                    
 
                          
 
memory limit per test 

256 megabytes

input

standard input

output

standard output

Recently, Masha was presented with a chessboard with a height of nn and a width of mm.

The rows on the chessboard are numbered from 11 to nn from bottom to top. The columns are numbered from 11 to mm from left to right. Therefore, each cell can be specified with the coordinates (x,y)(x,y), where xx is the column number, and yy is the row number (do not mix up).

Let us call a rectangle with coordinates (a,b,c,d)(a,b,c,d) a rectangle lower left point of which has coordinates (a,b)(a,b), and the upper right one — (c,d)(c,d).

The chessboard is painted black and white as follows:

An example of a chessboard.

Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x1,y1,x2,y2)(x1,y1,x2,y2). Then after him Denis spilled black paint on the rectangle (x3,y3,x4,y4)(x3,y3,x4,y4).

To spill paint of color colorcolor onto a certain rectangle means that all the cells that belong to the given rectangle become colorcolor. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).

Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!

Input

The first line contains a single integer tt (1≤t≤1031≤t≤103) — the number of test cases.

Each of them is described in the following format:

The first line contains two integers nn and mm (1≤n,m≤1091≤n,m≤109) — the size of the board.

The second line contains four integers x1x1, y1y1, x2x2, y2y2 (1≤x1≤x2≤m,1≤y1≤y2≤n1≤x1≤x2≤m,1≤y1≤y2≤n) — the coordinates of the rectangle, the white paint was spilled on.

The third line contains four integers x3x3, y3y3, x4x4, y4y4 (1≤x3≤x4≤m,1≤y3≤y4≤n1≤x3≤x4≤m,1≤y3≤y4≤n) — the coordinates of the rectangle, the black paint was spilled on.

Output

Output tt lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.

Example
input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
output
0 4
3 9
2 3
8 8
4 8

Explanation for examples:

The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).

In the first test, the paint on the field changed as follows:

In the second test, the paint on the field changed as follows:

 In the third test, the paint on the field changed as follows:

In the fourth test, the paint on the field changed as follows:

In the fifth test, the paint on the field changed as follows:

题意:题意给你一个n*m个矩形,里面有n*m个黑白色的小方块,分布如图所给的那样,然后划分区间将其全部变为白色,然后再划一个区间,将其全部变为黑色,

然后让你求,最后黑色白色的个数;

题解:(暴力肯定不行的),我们首先计算出划分第一个区间时,计算出白色的增加量ans+=cnt,然后再判断两个划分区间是否相交,如果相交,我们先将第一次划分中的黑色

变为白色的恢复成黑色,(就是白色的数量减去相交部分黑色的数量),然后我们计算第二次划分白色减少的数量,ans-=cnt1;就得到了最终白色的数量,则sum-ans即为黑色的数量。

(注意开long long)窝就是没开long long WA了一发,这一题只要仔细分析,代码认真就没啥问题Orz;

参考代码:

 #include<bits/stdc++.h>
using namespace std;
#define cls(x, val) memset(x,val,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
const int INf=0x3f3f3f3f;
ll T,n,m,l1,r1,l2,r2,x1,x2,y,y2;
int main()
{
scanf("%lld",&T);
while(T--)
{
scanf("%lld%lld",&n,&m);
scanf("%lld%lld%lld%lld",&l1,&r1,&l2,&r2);
scanf("%lld%lld%lld%lld",&x1,&y,&x2,&y2);
ll ans1=n*m/;//black
ll ans2=n*m-ans1;//white
if(((l2-l1+)&) && ((r2-r1+)&))
{
if((l1&)&&(r1&) || (!(l1&))&&(!(r1&))) ans2+=(r2-r1+)*(l2-l1+)/;
else ans2+=(r2-r1+)*(l2-l1+)/+(r2-r1+)*(l2-l1+)%;
}
else ans2+=(r2-r1+)*(l2-l1+)/;
if(!(x2<l1 || y2<r1 || l2<x1 || r2<y) )
{
ll cx=max(l1,x1),cy=max(r1,y);
ll ccx=min(l2,x2),ccy=min(r2,y2);
if((cx&)&&(cy&) || (!(cx&)) && (!(cy&))) ans2-=(ccx-cx+)*(ccy-cy+)/;
else ans2-=(ccx-cx+)*(ccy-cy+)/+(ccx-cx+)*(ccy-cy+)%;
}
if(((x2-x1+)&) && ((y2-y+)&))
{
if((x1&)&&(y&) || (!(x1&))&&(!(y&)))
ans2-=(y2-y+)*(x2-x1+)/+(y2-y+)*(x2-x1+)%;
else ans2-=(y2-y+)*(x2-x1+)/;
}
else ans2-=(y2-y+)*(x2-x1+)/;
printf("%lld %lld\n",ans2,n*m-ans2);
}
return ;
}
 
                            D. Olya and magical square

          
 
                                
 
                            time limit per test 

1 second

        
 
               
 
                            memory limit per test 

256 megabytes

input

standard input

output

standard output

Recently, Olya received a magical square with the size of 2n×2n2n×2n.

It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly kk splitting operations.

A Splitting operation is an operation during which Olya takes a square with side aa and cuts it into 4 equal squares with side a2a2. If the side of the square is equal to 11, then it is impossible to apply a splitting operation to it (see examples for better understanding).

Olya is happy to fulfill her sister's request, but she also wants the condition of Olya's happiness to be satisfied after all operations.

The condition of Olya's happiness will be satisfied if the following statement is fulfilled:

Let the length of the side of the lower left square be equal to aa, then the length of the side of the right upper square should also be equal to aa. There should also be a path between them that consists only of squares with the side of length aa. All consecutive squares on a path should have a common side.

Obviously, as long as we have one square, these conditions are met. So Olya is ready to fulfill her sister's request only under the condition that she is satisfied too. Tell her: is it possible to perform exactly kk splitting operations in a certain order so that the condition of Olya's happiness is satisfied? If it is possible, tell also the size of the side of squares of which the path from the lower left square to the upper right one will consist.

Input

The first line contains one integer tt (1≤t≤1031≤t≤103) — the number of tests.

Each of the following tt lines contains two integers nini and kiki (1≤ni≤109,1≤ki≤10181≤ni≤109,1≤ki≤1018) — the description of the ii-th test, which means that initially Olya's square has size of 2ni×2ni2ni×2ni and Olya's sister asks her to do exactly kiki splitting operations.

Output

Print tt lines, where in the ii-th line you should output "YES" if it is possible to perform kiki splitting operations in the ii-th test in such a way that the condition of Olya's happiness is satisfied or print "NO" otherwise. If you printed "YES", then also print the log2log2 of the length of the side of the squares through space, along which you can build a path from the lower left square to the upper right one.

You can output each letter in any case (lower or upper).

If there are multiple answers, print any.

Example
input
3
1 1
2 2
2 12
output
YES 0
YES 1
NO

In each of the illustrations, the pictures are shown in order in which Olya applied the operations. The recently-created squares are highlighted with red.

In the first test, Olya can apply splitting operations in the following order:

Olya applies one operation on the only existing square.

 The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one:

The length of the sides of the squares on the path is 11. log2(1)=0log2(1)=0.

In the second test, Olya can apply splitting operations in the following order:

Olya applies the first operation on the only existing square. She applies the second one on the right bottom square.

The condition of Olya's happiness will be met, since there is a path of squares of the same size from the lower left square to the upper right one:

The length of the sides of the squares on the path is 22. log2(2)=1log2(2)=1.

In the third test, it takes 55 operations for Olya to make the square look like this:

Since it requires her to perform 77 splitting operations, and it is impossible to perform them on squares with side equal to 11, then Olya cannot do anything more and the answer is "NO".

题意:给你一个2^n*2^n的方块,每一次选一个正方形把他分成四块,一共k步问最后是否可以让最后的左下角方块的大小等于右上角方块的大小,而且可以从左下角沿着同样大小的方块走到右上角.

题解:

  最后的路径一定可以是沿着边界走到右上角,只要路径上大小固定,就可以算出其它块可以分裂的次数,所以只要动态维护当前分裂次数a和可以分裂的次数b,如果当前分裂次数已经>k则不满足,否则如果出现a<=k&&a+b>=k说明有满足情况的答案。

  动态维护分裂的过程需要维护好多个变量,首先要维护路径的长度,这样也就知道去除路径剩多少个可分裂的块。还要维护左下角块的大小,也就知道可分裂次数。之后动态维护a,b就可以了。

 参考代码:

 #include<bits/stdc++.h>
using namespace std;
long long n,k;
int main()
{
long long T;cin>>T;
while(T--)
{
cin>>n>>k;
long long cnt=,tmp=n;
while(cnt<=k&&tmp)
{
--tmp; k-=cnt;
cnt=*cnt+;
}
for(long long sl=,x=n-;x>=tmp;--x,sl=sl*+)
{
for(long long tmp2=x,cnt2=;tmp2&&k>;--tmp2,cnt2*=) k-=sl*cnt2;
if(k<=) break;
}
if(k>) cout<<"NO"<<endl;
else cout<<"YES"<<' '<<tmp<<endl;
}
return ;
}

菜鸡就只会写4题,QwQ.

后面两题挖坑...

CodeForces-Round524 A~D的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

  10. CodeForces - 453A Little Pony and Expected Maximum

    http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= ...

随机推荐

  1. go中的数据结构字典-map

    1. map的使用 golang中的map是一种数据类型,将键与值绑定到一起,底层是用哈希表实现的,可以快速的通过键找到对应的值. 类型表示:map[keyType][valueType] key一定 ...

  2. Unity 简记(1)--TileMap

    ## Tilemap是unity中自带的快速构建2D场景的工具,优点是省时省力, 1 使用方法 在场景创建一个Tilemap 打开TilePalette ​ 3.创建一个新的Palette,将地图切割 ...

  3. maven的项目结构

    1.标准目录结构: src -main       –bin 脚本库       –java java源代码文件       –resources 资源库,会自动复制到classes目录里       ...

  4. 详细讲解 Redis 的两种安装部署方式

    Redis 是一款比较常用的 NoSQL 数据库,我们通常使用 Redis 来做缓存,这是一篇关于 Redis 安装的文章,所以不会涉及到 Redis 的高级特性和使用场景,Redis 能够兼容绝大部 ...

  5. [LC]83题 Remove Duplicates from Sorted List(删除排序链表中的重复元素)(链表)

    ①英文题目 Given a sorted linked list, delete all duplicates such that each element appear only once. Exa ...

  6. [LC]35题 Search Insert Position (搜索插入位置)

    ①英文题目 Given a sorted array and a target value, return the index if the target is found. If not, retu ...

  7. 领扣(LeetCode)找树左下角的值 个人题解

    给定一个二叉树,在树的最后一行找到最左边的值. 示例 1: 输入: 2 / \ 1 3 输出: 1 示例 2: 输入: 1 / \ 2 3 / / \ 4 5 6 / 7 输出: 7 注意: 您可以假 ...

  8. FIddler+Proxifer工具对windows PC客户端进行抓包

    python的大火,带动了python爬虫. 爬虫就必定绕不开抓包. 目前最常见的就是网页抓包了,可以使用chrome进行,或者配合其他抓包软件 fiddler. 小程序有些兴起是,如跳一跳之类的,也 ...

  9. python_08

    一.作业 ''' 主页: 图标地址.下载次数.大小.详情页地址 详情页: 游戏名.好评率.评论数.小编点评.下载地址.简介.网友评论.1-5张截图链接地址. https://www.wandoujia ...

  10. Nginx+SpringBoot实现负载均衡

    前言 在上一篇中介绍了Nginx的安装,本篇文章主要介绍的是Nginx如何实现负载均衡. 负载均衡介绍 介绍 在介绍Nginx的负载均衡实现之前,先简单的说下负载均衡的分类,主要分为硬件负载均衡和软件 ...