A. Petya and Origami
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Petya is having a party soon, and he has decided to invite his n 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 k sheets. That is, each notebook contains k sheets of either red, green, or blue.

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

Input
The first line contains two integers n and k (1≤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
inputCopy
3 5
outputCopy
10
inputCopy
15 6
outputCopy
38
Note
In the first example, we need 2 red notebooks, 3 green notebooks, and 5 blue notebooks.

In the second example, we need 5 red notebooks, 13 green notebooks, and 20 blue notebooks.

题解:petya有n个朋友,他想邀请他们,制作一个请帖需要2个红纸片,5个绿的,8个蓝的。一个笔记本上只有一种颜色,有k张纸片,问他总共需要购买几个笔记本。

n*2就是需要的红纸片个数,再除以k,再向上取整,就是需要这种颜色的笔记本的个数。三种颜色的个数加起来就是了。

#include <cstdio>
#include <cmath> int main(){
int n,k;
while(~scanf("%d %d",&n,&k)){
int sum=;
sum+=(int)ceil((n**1.0)/k);
sum+=(int)ceil((n**1.0)/k);
sum+=(int)ceil((n**1.0)/k);
printf("%d\n",sum); }
}
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

Copy
5
1 3
2 5
5 5
4 4
2 3
output

Copy
-2
-2
-5
4
-1
Note

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.

思路:题意很清楚了,有个数组,每个数如那个公式所述。输入l,r,求这一段中间的数字之和。

刚开始很容易想到挨着加起来,但是当输入是 1 1e9的时候,就会超时,所以要找规律。

然后可以起点终点可以分别是相同的时候, 奇奇 奇偶 偶奇 偶偶 的时候,写出公式即可。

 #include <stdio.h>

 int main(){
int q,l,r;
scanf("%d",&q);
while(q--){
scanf("%d %d",&l,&r);
long long sum=;
if(l==r){
if(l%==){
sum=l;
}else{
sum=-*l;
}
}
if(l%==&&r%==) sum=(r-l)/+(-*r);
if(l%==&&r%==) sum=(r+-l)/;
if(l%==&&r%==) sum=r-(r-l)/;
if(l%==&&r%==) sum=-*(r+-l)/;
/*for(int i=l;i<=r;i++){
if(i%2==0){
sum+=i;
}else{
sum+=(-1*i);
}
}*/
printf("%lld\n",sum);
}
}

Codeforces Round #524 (Div. 2)的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. Codeforces Round #524 (Div. 2) F. Katya and Segments Sets(主席树)

    https://codeforces.com/contest/1080/problem/F 题意 有k个区间,区间的种类有n种,有m个询问(n,m<=1e5,k<=3e5),每次询问a,b ...

  3. Codeforces Round #524 (Div. 2) E. Sonya and Matrix Beauty(字符串哈希,马拉车)

    https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每 ...

  4. Codeforces Round #524 (Div. 2) C. Masha and two friends(矩形相交)

    C. Masha and two friends time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. Codeforces Round #524 (Div. 2) B. Margarite and the best present

    B. Margarite and the best present 题目链接:https://codeforces.com/contest/1080/problem/B 题意: 给出一个数列:an=( ...

  6. Codeforces Round #524 (Div. 2) D. Olya and magical square

    D. Olya and magical square 题目链接:https://codeforces.com/contest/1080/problem/D 题意: 给出一个边长为2n的正方形,每次可以 ...

  7. Codeforces Round #524 (Div. 2) codeforces 1080A~1080F

    目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...

  8. Codeforces Round #524 (Div. 2)C 二维坐标系求俩矩形面积交

    题:https://codeforces.com/contest/1080/problem/C 题意:给n*m的二维坐标系,每个位置(xi,yi)都表示一个方格,(1,1)的位置是白色,整个坐标系黑白 ...

  9. Codeforces Round #524 (Div. 2) F

    题解: 首先这个东西因为强制在线区间查询 所以外面得套线段树了 然后考虑几条线段怎么判定 我们只需要按照右端点排序,然后查询的时候查找最右节点的前缀最大值就可以了 然后怎么合并子区间信息呢 (刚开始我 ...

随机推荐

  1. 轴对称 Navier-Stokes 方程组的点态正则性准则 II

    在 [Wei, Dongyi. Regularity criterion to the axially symmetric Navier-Stokes equations. J. Math. Anal ...

  2. react中input自动聚焦问题

    input自动聚焦问题 在react中可以使用refs解决这个问题,首先看一下refs的使用场景: (1)处理焦点.文本选择或媒体控制. (2)触发强制动画. (3)集成第三方 DOM 库. 使用re ...

  3. 基于STM32F1的语音合成芯片SYN6288驱动

    目录 说明 SYN6288.h SYN6288.c 说明 基于USART2制作,封装了各种通信协议 SYN6288.h #ifndef _SYN6288_H_ #define _SYN6288_H_ ...

  4. SQL Server2016安装

    VS2017已经发布10多天了,这几天正好要重新做系统.所以想着把SQL Server和VS都做一次升级.VS2017只需要下载一个安装包就可以进行在线安装.但是SQL Server2016安装时会碰 ...

  5. Hadoop cloudera版和Apache(原生态)的区别

    ---------------------------------------------------------------------------------------------------- ...

  6. eclipse 报错问题:java.lang.ClassNotFoundException:

    解决方法:https://www.cnblogs.com/whatlonelytear/articles/5921978.html

  7. 论文阅读笔记四十四:RetinaNet:Focal Loss for Dense Object Detection(ICCV2017)

    论文原址:https://arxiv.org/abs/1708.02002 github代码:https://github.com/fizyr/keras-retinanet 摘要 目前,具有较高准确 ...

  8. DOS批处理高级教程(还不错)(转)

    前言 目录 第二节 常用特殊符号     1.@  命令行回显屏蔽符     2.%  批处理变量引导符     3.>   输出重定向符     4.>>  输出重定向符     ...

  9. css_base_note

  10. Cpp Generals 1.2

    原文链接https://www.cnblogs.com/zhouzhendong/p/Cpp-Generals.html 源码暂不公开 下载链接 适用系统: Windows: 运行时请在进入彩色界面之 ...