2021-01-29

题目链接: Educational Codeforces Round 103 (Rated for Div. 2)

题目

A. K-divisible Sum

You are given two integers nn and kk.

You should create an array of nn positive integers a1,a2,…,ana1,a2,…,an such that the sum (a1+a2+⋯+an)(a1+a2+⋯+an) is divisible by kk and maximum element in aa is minimum possible.

What is the minimum possible maximum element in aa?

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

The first and only line of each test case contains two integers nn and kk (1≤n≤1091≤n≤109; 1≤k≤1091≤k≤109).

Output

For each test case, print one integer — the minimum possible maximum element in array aa such that the sum (a1+⋯+an)(a1+⋯+an) is divisible by kk.

Example
input

Copy
4
1 5
4 3
8 8
8 17
output

Copy
5
2
1
3
Note

In the first test case n=1n=1, so the array consists of one element a1a1 and if we make a1=5a1=5 it will be divisible by k=5k=5 and the minimum possible.

In the second test case, we can create array a=[1,2,1,2]a=[1,2,1,2]. The sum is divisible by k=3k=3 and the maximum is equal to 22.

In the third test case, we can create array a=[1,1,1,1,1,1,1,1]a=[1,1,1,1,1,1,1,1]. The sum is divisible by k=8k=8 and the maximum is equal to 11.


思路:

大致看来,分三个情况: (带==>就是说的结果)

    1. n=k, ==>1

    2. n<k,数大被分的少 ,  结果就是, (k-1) / 2 + 1 

     比如9~16被分为8份==>2;   17~24被分8份==>3  

    3. n>k, 数小被分的多, 这里还分两种情况

       1). n是k的整倍数 ==> 1,  可以与第一种情况合并.

     2). else ==>2 比如 n = 3时, k=4  ->1, 1, 2, 2;

                    k=5 ->1, 1, 2, 2, 3  把最后的3补到前面->1, 2, 2, 2, 2 化简-> 1, 1, 1, 1, 2

                 k=6, ==> n是k的倍数 ==>1

      总而言之, 1和2就能搞定, 所以结果==>2

AC代码

#include <iostream>

using namespace std;int main()
{
int t;
cin >> t;
while(t --)
{
int n, num;
cin >> n >> num; if(n % num == 0)
cout << 1 << endl;
else
{
int ans;
if(n > num)
ans = 2;
else
ans = (num + n - 1) / n;
cout << ans << endl;
}
cout << endl;
}
return 0;
}

 
B. Inflation(贪心)

You have a statistic of price changes for one product represented as an array of nn positive integers p0,p1,…,pn−1p0,p1,…,pn−1, where p0p0 is the initial price of the product and pipi is how the price was increased during the ii-th month.

Using these price changes you are asked to calculate the inflation coefficients for each month as the ratio of current price increase pipi to the price at the start of this month (p0+p1+⋯+pi−1)(p0+p1+⋯+pi−1).

Your boss said you clearly that the inflation coefficients must not exceed kk %, so you decided to increase some values pipi in such a way, that all pipi remain integers and the inflation coefficients for each month don't exceed kk %.

You know, that the bigger changes — the more obvious cheating. That's why you need to minimize the total sum of changes.

What's the minimum total sum of changes you need to make all inflation coefficients not more than kk %?

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

The first line of each test case contains two integers nn and kk (2≤n≤1002≤n≤100; 1≤k≤1001≤k≤100) — the length of array pp and coefficient kk.

The second line of each test case contains nn integers p0,p1,…,pn−1p0,p1,…,pn−1 (1≤pi≤1091≤pi≤109) — the array pp.

Output

For each test case, print the minimum total sum of changes you need to make all inflation coefficients not more than kk %.

Example
input

Copy
2
4 1
20100 1 202 202
3 100
1 1 1
output

Copy
99
0
Note

In the first test case, you can, for example, increase p0p0 by 5050 and p1p1 by 4949 and get array [20150,50,202,202][20150,50,202,202]. Then you get the next inflation coefficients:

  1. 5020150≤11005020150≤1100;
  2. 20220150+50≤110020220150+50≤1100;
  3. 20220200+202≤110020220200+202≤1100;

In the second test case, you don't need to modify array pp, since the inflation coefficients are already good:

  1. 11≤10010011≤100100;
  2. 11+1≤10010011+1≤100100;

题意:

从a2开始,每个值的计算方式为:pi=ai/(a0+a1+a2+...+ai-1)

使得每个pi都<=k/100的最少增加值之和

可惜啊, 做了一半困得没再做, 当时代码出了点bug, 点写在代码里了

AC代码

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll p[110], bottom, top, res;

int main()
{
int t;
cin >> t;
while(t --)
{
int n, k;
res = 0;
cin >> n >> k;
for(int i = 0 ; i< n; i ++)
cin >> p[i]; bottom = 0;
for(int i = 0; i < n - 1; i ++)
{
bottom += p[i];
top = p[i + 1];
if(bottom * k < 100 * top)
{
ll d = 100 * top / k - bottom;//这里切记用long long
if(100 * top % k != 0)//有余数+1
d ++;
res += d;
bottom += d;
}
}
cout << res << endl;
}
return 0;
}

Edu CF 103 Div. 2 (A. K-divisible Sum, B. Inflation贪心),被黑客攻了,,惨掉rank, 思维除法与取余, 不太擅长的类型的更多相关文章

  1. Codeforces Round #667 (Div. 3) D. Decrease the Sum of Digits (贪心)

    题意:给你一个正整数\(n\),每次可以对\(n\)加一,问最少操作多少次是的\(n\)的所有位数之和不大于\(s\). 题解:\(n\)的某个位置上的数进位,意味这后面的位置都可以被更新为\(0\) ...

  2. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  3. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  4. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

  5. CF #374 (Div. 2) C. Journey dp

    1.CF #374 (Div. 2)    C.  Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...

  6. CF #371 (Div. 2) C、map标记

    1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...

  7. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组

    题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...

  8. CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)

    转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...

  9. 最短路 Codeforces Round #103 (Div. 2) D. Missile Silos

    题目传送门 /* 最短路: 不仅扫描边,还要扫描点:点有两种情况,一种刚好在中点,即从u,v都一样,那么最后/2 还有一种是从u,v不一样,两种的距离都是l 模板错了,逗了好久:( */ #inclu ...

随机推荐

  1. 旅游清单一步搭建,Angular助力你的踏春计划

    春天的脚步愈发临近,相信很多小伙伴已经开始规划自己的踏春计划了,无论是欣赏名胜古迹,还是走访风土人文,你都需要提前准备一份旅游清单!有了这款Angular旅游计划应用,从地点到预算,它都能帮助你创建自 ...

  2. CEPH-2:rbd功能详解及普通用户应用ceph集群

    ceph集群rbd使用详解 一个完整的ceph集群,可以提供块存储.文件系统和对象存储. 本节主要介绍rbd存储功能如何灵活的使用,集群背景: $ ceph -s cluster: id: 53717 ...

  3. JVM知识(一) 求你了,别再说Java对象都是在堆内存上分配空间的了!

    求你了,别再说Java对象都是在堆内存上分配空间的了! https://baijiahao.baidu.com/s?id=1661296872935371634&wfr=spider& ...

  4. 什么是 CSRF 攻击?

    CSRF 代表跨站请求伪造.这是一种攻击,迫使最终用户在当前通过身份验证的 Web 应用程序上执行不需要的操作.CSRF 攻击专门针对状态改变请求,而不是 数据窃取,因为攻击者无法查看对伪造请求的响应 ...

  5. JPA、JTA、XA相关索引

    JPA和分布式事务简介:https://www.cnblogs.com/onlywujun/p/4784233.html JPA.JTA与JMS区别:https://www.cnblogs.com/y ...

  6. MyBatis 实现一对一有几种方式?具体怎么操作的?

    有联合查询和嵌套查询,联合查询是几个表联合查询,只查询一次, 通过在 resultMap 里面配置 association 节点配置一对一的类就可以完成: 嵌套查询是先查一个表,根据这个表里面的结果的 ...

  7. 学习FastDfs(四)

    1.简介 FastDFS 是一个开源的高性能分布式文件系统(DFS). 它的主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载平衡.主要解决了海量数据存储问题,特别适合以中小文件(建议范围: ...

  8. 阿里低代码引擎 | LowCodeEngine - 如何配置并调用请求

    首发于 语雀文档@blueju 前言 发送请求是前端中很重要也很常见的一部分,阿里低代码引擎自然也不会缺少这一块.在阿里低代码引擎中,请求是在数据源中配置,数据源位置如下图: 配置 配置界面如下图:其 ...

  9. NE555脉冲模块电路

  10. 解决使用 swiper 常见的问题

    使用 swiper 的过程中个人总结 1. swiper插件使用方法, 直接查看文档 swiper基础演示 swiper API文档 2.swiper近视初始化时, 其父级元素处于隐藏状态(displ ...