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. SpringBoot(七):SpringBoot整合Swagger2

    原文地址:https://blog.csdn.net/saytime/article/details/74937664 手写Api文档的几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文 ...

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

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

  3. Sql server not in优化

    使用EXISTS(或NOT EXISTS)通常将提高查询的效率,由于NOT IN子句将对子查询中的表执行了一个全表遍历. oracle在执行IN子查询过程中,先执行子查询结果放入临时表再进行主查询: ...

  4. 用sklearn 实现linear regression

    基本的regression算法有四种方法可以实现,分别是下面四种 LinearRegressionRidge (L2 regularization)Lasso (L1 regularization)E ...

  5. c#管理文件系统

    using System; using System.Collections.Generic; using System.IO; using static System.Console; /*Syst ...

  6. MATLAB更换编辑器配色方案

    MATLAB的默认编辑配色方案白色,长时间面对高亮度的白色界面容易产生眼睛疲劳的感觉,那么如何更换编辑器配色方案呢?经过不断探索以及查阅资料,发现了下列几种配色方案.配色文件来源于https://gi ...

  7. TIME_WAIT 太多的解决办法

    TIME_WAIT 客户端与服务器端建立TCP/IP连接后关闭SOCKET后,服务器端连接的端口状态为TIME_WAIT.主动关闭的一方在发送最后一个 ack 后 就会进入 TIME_WAIT 状态  ...

  8. css杂项补充

    css杂项补充 一.块与内联 1.块 独行显示 支持宽高,宽度默认适应父级,高度默认由子级或内容撑开 设置宽高后,采用设置的宽高 2.内联 同行显示 不支持宽高 margin上下无效果,左右会起作用, ...

  9. CSS之文本

    文本对齐方式 text-align left 把文本排列到左边. 默认值:由浏览器决定. right 把文本排列到右边. center 把文本排列到中间. justify 实现两端对齐文本效果. in ...

  10. 微软拼音转换工具类ChnCharInfo.dll

    1.简介 之前做汉字转拼音是使用各种枚举的方式,将各种情况列举,这种方式出错的机率很大,经常对不上号.(如果你想了解更多:http://www.cnblogs.com/islands/articles ...