OUC_Summer Training_ DIV2_#11 722
企鹅很忙系列~(可惜只会做3道题T_T)
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r).
He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment[l - 1; r], or to segment [l; r + 1].
The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.
Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.
Input
The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li andri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space.
It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds,min(ri, rj) < max(li, lj).
Output
In a single line print a single integer — the answer to the problem.
Sample Input
2 3
1 2
3 4
2
3 7
1 2
3 3
4 7
0
这个题我看了好久才明白意思啊,英语真拙计,核心意思就是先给出一个数K,再给出n个区间,使得这n个区间的整数的个数和能整除k,如果不能,就要做改变,每一次改变只能增加一个整数,回答最少需要做改变的次数。
#include<stdio.h>
int main()
{
int sum = ,n,k,a,b,i,j;
scanf("%d%d",&n,&k);
while(n--)
{
scanf("%d%d",&a,&b);
sum += b - a + ;
}
if(sum % k == )printf("0\n");
else
{
printf("%d\n",k - sum %k);//k减去k的余数就是这个数还要加几才能达到k,该题中就是要改变的次数
}
return ;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Little penguin Polo has an n × m matrix, consisting of integers. Let's index the matrix rows from 1 to n from top to bottom and let's index the columns from 1 to m from left to right. Let's represent the matrix element on the intersection of row i and column j as aij.
In one move the penguin can add or subtract number d from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
Input
The first line contains three integers n, m and d (1 ≤ n, m ≤ 100, 1 ≤ d ≤ 104) — the matrix sizes and the d parameter. Next n lines contain the matrix: the j-th integer in the i-th row is the matrix element aij (1 ≤ aij ≤ 104).
Output
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
Sample Input
2 2 2
2 4
6 8
4
1 2 7
6 7
-1
给一个M*N的矩阵及一个数D,小企鹅喜欢矩阵,但是喜欢每个数都一样,不过它每次都只能把矩阵中的数加或者减D,输出最少的改变次数,使矩阵的数变成一样的。如果不能达到目标就输出-1,否则输出最少的次数。
用一维数组存矩阵好了(有时候不要被题目欺骗了,一维数组就能做的时候不要只想着开二维数组),然后把数组排序,中间的数就是所有的数希望变成的数(这样改变的次数才能最小)。然后计算次数。最后要说一下怎么判断这个数组不能达到目标呢。因为我写的代码是在存入数组的时候就要判断是否能达到目标,这个时候还不知道所有的数希望变成的数是什么。不如设所有的数希望变成的数是m好了,则a1 + n1 * d = m,a2 + n2 * d = m,两式相减可得(a1 - a2) / d = n2 - n1由此可以得到矩阵中任两个数的差一定是d的倍数,如果存在不是这样的数,则这个矩阵就不符合要求。
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[];
int main()
{ int m,n,d,i,x,y = ,sum = ;
cin >> m>> n>> d;
for(i = ;i < n*m;i++)
{
cin >> a[i];
if(i == )continue;
else if((a[i] - a[i - ]) % d != && y==)
{
y = ;
}
}
if(y == )cout << -<<endl;
else
{
sort(a,a+n*m);
int mid = n*m /;
for(i = ;i < n*m;i++)
{
x = abs(a[mid] - a[i]);
sum += x/d;
}
cout << sum<<endl;
}
return ;
}
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Little penguin Polo adores strings. But most of all he adores strings of length n.
One day he wanted to find a string that meets the following conditions:
- The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct.
- No two neighbouring letters of a string coincide; that is, if we represent a string as s = s1s2... sn, then the following inequality holds, si ≠ si + 1(1 ≤ i < n).
- Among all strings that meet points 1 and 2, the required string is lexicographically smallest.
Help him find such string or state that such string doesn't exist.
String x = x1x2... xp is lexicographically less than string y = y1y2... yq, if either p < q and x1 = y1, x2 = y2, ... , xp = yp, or there is such number r(r < p, r < q), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes.
Input
A single line contains two positive integers n and k(1 ≤ n ≤ 106, 1 ≤ k ≤ 26) — the string's length and the number of distinct letters.
Output
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
Sample Input
7 4
ababacd
4 7
-1
小企鹅喜欢字符串,给定字符串长度n,字符串中还必须包括k个不同的字符,相邻字符还不一样。输出符合这些条件的最小字符(按字典序排列)。很明显字符串前面肯定是ab的组合,在结尾递增的加上剩余字符即可。这个题要注意的地方有 除了1 1输出是a外,其他k == 1时输出都为-1,因为不能用一个字符组成一个前后字符不相等的字符串。(虽然是很浅显的特殊情况,但有时候就是容易忽略,今后要避免这样的情况发生)。
不过这个题我要抱怨一下,一开始编译的时候,str[i] = str[i - 1] + 1;这行代码得到的不是我想要的结果,除了前面的ab其他的打印出来都是笑脸,你难道想让我陪你玩一会在提交?笑什么笑。。。不过后来在演示这一奇葩现象的时候又恢复了正常了。亏我在代码中还用了强制转换,其实根本用不上好吗。
#include<stdio.h>
char str[];
int main()
{
int n,k,i,j,m;
scanf("%d%d",&n,&k);
if(n == && k==)printf("a\n");
else if(k > n || k==)printf("-1\n");
else if(k == n)
{
for(i = ;i < n;i++)
{
if(i == )
str[] = 'a';
else
str[i] = (char)((int)str[i-] +);
}
str[n] = '\0';
printf("%s\n",str);
}
else if(k < n)
{
m =n - (k - );
if(m % == )
{
for(i = ;i < m-;i = i+)
{
str[i] = 'a';
str[i+] = 'b';
}
for(;i < n;i++)
str[i] = (char)((int)str[i-] +);
}
else
{
for(i = ;i < m-;i = i+)
{
str[i] = 'a';
str[i+] = 'b';
}
str[i++] = 'a';
str[i++] = 'c';
for(;i < n;i++)
str[i] = (char)((int)str[i-] +);
}
str[n] = '\0';
printf("%s\n",str);
}
return ;
}
当然,这个题不用字符串存起来也行,可惜当时只想到用字符串的方法。
感觉自己写题解废话越来越多了,多写上了自己的感受,和wa的原因,主要还是因为写的这些东西都是为了留下纪念,所以废话多一点的话今后看起来比较亲切。若有路过的大神不要嫌弃啊(其实我这些渣题不会有大神来看的啦~)。
OUC_Summer Training_ DIV2_#11 722的更多相关文章
- OUC_Summer Training_ DIV2_#14 724
又落下好多题解啊...先把今天的写上好了. A - Snow Footprints Time Limit:1000MS Memory Limit:262144KB 64bit IO F ...
- OUC_Summer Training_ DIV2_#16 725
今天做了这两道题真的好高兴啊!!我一直知道自己很渣,又贪玩不像别人那样用功,又没有别人有天赋.所以感觉在ACM也没有学到什么东西,没有多少进步.但是今天的B题告诉我,进步虽然不明显,但是只要坚持努力的 ...
- OUC_Summer Training_ DIV2_#13 723afternoon
A - Shaass and Oskols Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- OUC_Summer Training_ DIV2_#12(DP1) 723
这一次是做练习,主要了解了两个算法,最大子矩阵和,最长上升子序列. 先看题好啦. A - To The Max Time Limit:1000MS Memory Limit:32768KB ...
- OUC_Summer Training_ DIV2_#2之解题策略 715
这是第一天的CF,是的,我拖到了现在.恩忽视掉这个细节,其实这一篇只有一道题,因为这次一共做了3道题,只对了一道就是这一道,还有一道理解了的就是第一篇博客丑数那道,还有一道因为英语实在太拙计理解错了题 ...
- OUC_Summer Training_ DIV2_#7 718
是18号做的题啦,现在才把报告补上是以前不重视报告的原因吧,不过现在真的很喜欢写报告,也希望能写一些有意义的东西出来. A - Dragons Time Limit:2000MS Memory ...
- OUC_Summer Training_ DIV2_#9 719
其实自己只会做很简单的题,有时都不想写解题报告,觉得不值得一写,但是又想到今后也许就不会做ACM了,能留下来的东西只有解题报告了,所以要好好写,很渣的题也要写,是今后的纪念. B - B Time L ...
- OUC_Summer Training_ DIV2_#5
这是做的最好的一次了一共做了4道题 嘻嘻~ A - Game Outcome Time Limit:2000MS Memory Limit:262144KB 64bit IO For ...
- OUC_Summer Training_ DIV2_#4之数据结构
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26100#problem/A A - A Time Limit:1000MS Me ...
随机推荐
- NVIDIA双显卡
NVIDIA双显卡 第一步:代码:sudo update-pciids #更新显卡信息非常重要,否则可能识别出错lspci -v | grep -i vga #察看显卡 我的显卡信息如下:代码:00: ...
- UPX编译及so加固
UPX编译及so加固 来源 https://www.cnblogs.com/Reverser/p/5778042.html 参考 http://www.cnblogs.com/fishou/p/420 ...
- VUE实现简单的全选/全不选
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- HTML Ueditor图片宽度超出编辑器
问题描述 Ueditor上传图片宽度尺寸超出编辑器宽度,显示异常 解决方案 ueditor.all.js 添加img宽度限制(搜索body{margin:8px;font-family:sans-se ...
- Javascript简单教程汇总
什么是函数 一段定义好的代码,并可以反复使用的代码块 函数的作用 提升代码的可复用性,将一段代码进行预定义,需要使用的时候才触发 代码块 形成了一个相对独立的作用域 语法: function 函数名 ...
- Linux下mysql不区分大小写设置
Linux环境下的MySQL数据库的表名默认是区分大小写的 Windows环境下的MySQL数据库的表名默认是不区分大小写的 所以Linux下想mysql不区分下大写可以查看/etc/my.cnf文件 ...
- 使用nodejs实现OData的batch操作在Marketing Cloud里读取contact信息
我们先来看看Marketing Cloud系统里的contact信息: 一共1218374条数据. 我们用如下的nodejs代码通过OData来获取这些数据: var request = requir ...
- CRM WebClient UI的浏览器打印实现
WebClient UI上自带了一个打印按钮,按Ctrl + P后可以生成一个新的页面供打印. 如下图所示.可以看到这个页面里所有的超链接都已经被移除了. 这个页面的生成逻辑如下. 1. 按住ctrl ...
- Windows Phone惨遭微软放弃
微软在电脑操作系统上的用户保有量一直处于遥遥领先的地位,特别是最新的Windows 10系统,一经推出,市场表现就比较好,但相比起来,微软的手机操作系统Windows Phone就被贴上“差等生”的标 ...
- 01_Redis简述
一:关系型数据库和非关系型数据库的区别: 1:关系型数据库(SQL):数据和数据之间,表和字段之间,表和表之间是存在关系的: 优点:数据之间有关系,进行数据的增删改查时非常方便的:关系型数据库有事务操 ...