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. Linux如何添加硬盘

    一.命令操作: df       #查看磁盘空间 fdisk     #分区/查看分区 mkfs      #格式化 df  -h(以人类易读) -m(以M为单位读取)            #查看硬 ...

  2. Linux访问控制列表

    首先我们来了解下权限,在Linux里常规的权限有r(读)w(写)x(执行),特殊权限有SUID,SGID,Sticky权限,分别作用在文件(或目录)的所有者,所属组和其他(既不是所有者,也不是所属组的 ...

  3. WPF CefSharp 爬虫

    1.实际需求          EMS邮件的自动分拣,要分拣首先需要获取邮件的面单号和邮寄地址,现在我们的快递一般都有纸质面单的,如果是直接使用图像识别技术从纸质面单中获取信息,这个开发的成本和实时性 ...

  4. 使用火狐浏览器模仿手机浏览器,附浏览器HTTP_USER_AGENT汇总

    HTTP_USER_AGENT用来获取浏览页面的访问者在用什么操作系统(包括版本号)浏览器(包括版本号)和用户个人偏好. 改变浏览器的这个参数就可以伪装成相应的浏览器. User Agent Swit ...

  5. RabbitMQ 的高可用集群

    RabbitMQ 的高可用性 RabbitMQ 是比较有代表性的,因为是基于主从(非分布式)做高可用的 RabbitMQ 有三种模式:单机模式.普通集群模式.镜像集群模式. 单机模式 单机模式,生产几 ...

  6. thinkphp5配合datatable插件分页后端处理程序

    thinkphp5配合datatable插件分页后端处理程序第一版DataTable.php v.1.0 <?php use think\Db; /** * DataTable.php. */ ...

  7. hdu 1233 (prim,最小生成树) 还是畅通工程

    还是畅通工程Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. nyoj 44-子串和(子串和最大问题)

    44-子串和 内存限制:64MB 时间限制:5000ms Special Judge: No accepted:12 submit:48 题目描述: 给定一整型数列{a1,a2...,an},找出连续 ...

  9. Mysql 添加字段 修改字段 删除字段

    1.添加字段(alter.add) mysql> alter table users add name varchar(30) not null after id; 2.修改字段(alter.m ...

  10. 记录用户登陆信息,你用PHP是如何来实现的

    对于初入门的PHP新手来说,或许有一定的难度.建议大家先看看PHP中session的基础含义,需要的朋友可以选择参考. 下面我们就通过具体的代码示例,为大家详细的介绍PHP中session实现记录用户 ...