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. 微软的分布式应用框架 Dapr

    微服务架构已成为构建云原生应用程序的标准,微服务架构提供了令人信服的好处,包括可伸缩性,松散的服务耦合和独立部署,但是这种方法的成本很高,需要了解和熟练掌握分布式系统.为了使用所有开发人员能够使用任何 ...

  2. Laravel生命周期与原理

    一旦用户(浏览器)发送了一个HTTP请求,我们的apache或者nginx一般都转到index.php,因此,之后的一系列步骤都是从index.php开始的,我们先来看一看这个文件代码. <?p ...

  3. nyoj 455-黑色帽子

    455-黑色帽子 内存限制:64MB 时间限制:1000ms 特判: No 通过数:4 提交数:7 难度:1 题目描述:         最近发现了一个搞笑的游戏,不过目前还没玩过.一个舞会上,每个人 ...

  4. gitbook怎么操作

    首先我先说一下什么是GitBook,它和Git没半毛钱关系,定义如下: GitBook 是一个基于 Node.js 的命令行工具,支持 Markdown 和 AsciiDoc 两种语法格式,可以输出 ...

  5. 两步搞定Activity的向右滑动返回的功能

    向右滑动返回,对于屏幕过大的手机来说,在单手操作时,是一个不错的用户体验,用户不必再费力的或者用另一个手去点击屏幕左上角的返回按钮或者,手机右下角的返回按钮,轻轻向右滑动屏幕即可返回上一页,这个功能如 ...

  6. tcpip协议

    几个概念 1.分层(我们使用四层模型更为贴合我们的实际网络) 分层是为什么,其实和公司中职位是一样的,不同职位的人做不同的事情,然后不同职位的人合起来,一起完成了数据传输的事情. 链路层  在这个层面 ...

  7. JAVA _____Scanner用法

    今天就来说一说Scanner用法,以前我在学C的时候记得第一天学的是很普遍的HelloWord的输出,JAVA中的输出是这样子的, public class ScannerWriter { publi ...

  8. nginx-(三)基本模块1

    nginx常用模块介绍 ngx_http_access_module模块的配置(基于IP的访问控制) allow address | CIDR | unix: | all; deny address ...

  9. python网络爬虫之入门[一]

    目录 前言 一.探讨什么是python网络爬虫? 二.一个针对于网络传输的抓包工具fiddler 三.学习request模块来爬取第一个网页 * 扩展内容(爬取top250的网页) 后记 @(目录) ...

  10. 转载-FileZilla Server源码分析(1)

    FileZilla Server源码分析(1) 分类: VC 2012-03-27 17:32 2363人阅读 评论(0) 收藏 举报 serversocketftp服务器usersockets工作 ...