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. China-global view

    Good morning everyone. Everyone here would know this year Xia’Men held the BRICS business forum.In a ...

  2. HTML常用知识点代码演示

    1 HTML部分常用知识点 <!-- 版本声明 --> <!DOCTYPE html> <!-- 唯一根元素 --> <html> <!-- 对网 ...

  3. js中精度问题以及解决方案

    js中的数字按照IEEE 754的标准,使用64位双精度浮点型来表示.其中符号位S,指数位E,尾数位M分别占了1,11,52位,并且在ES5规范中指出了指数位E的取值范围是[-1074, 971]. ...

  4. (四)Java工程化--Git基础

    GIT学习参考:https://git-scm.com/book/zh/v2 常见命令 git init 初始化项目 git add *.java 添加文件到git版本控制(.java后缀的全部文件) ...

  5. mongoDB3.0版本使用express读取数据

    使用express连接数据库操作 var express = require('express'); var app = express(); var MongoClient = require('m ...

  6. 【转】利用apktool反编译apk,并且重新签名打包

    网站:https://ibotpeaches.github.io/Apktool,下载安装好apktool. 我的安装在 C:\Users\Administrator\Downloads\apktoo ...

  7. poj 2155 matrix 二维线段树 线段树套线段树

    题意 一个$n*n$矩阵,初始全为0,每次翻转一个子矩阵,然后单点查找 题解 任意一种能维护二维平面的数据结构都可以 我这里写的是二维线段树,因为四分树的写法复杂度可能会退化,因此考虑用树套树实现二维 ...

  8. zabbix批量监控域名下nginx的访问50x状态码数量

    背景: 购物车相关的站点某些页面经常出现502,如果超过一些阈值则需要报警给管理员知道 .自动发现脚本的编写 # vim /usr/local/zabbix_agents_3.2.0/scripts/ ...

  9. Elasticsearch JAVA api轻松搞定groupBy聚合

    本文给出如何使用Elasticsearch的Java API做类似SQL的group by聚合. 为了简单起见,只给出一级groupby即group by field1(而不涉及到多级,例如group ...

  10. 【原创】大数据基础之Spark(8)Spark中Join实现原理

    spark中join有两种,一种是RDD的join,一种是sql中的join,分别来看: 1 RDD join org.apache.spark.rdd.PairRDDFunctions /** * ...