第三十次codeforces竞技结束 #296 Div 2
Problems # Name A Playing with Paper standard input/output 2 s, 256 MB x2429 B Error Correct System standard input/output 2 s, 256 MB x953 C Glass Carving standard input/output 2 s, 256 MB x584 第三十次……好想到紫啊好想紫55555,两个1A,14
Problems
# | Name | ||
---|---|---|---|
A |
Playing with Paper
standard input/output 2 s, 256 MB |
x2429 | |
B |
Error Correct System
standard input/output 2 s, 256 MB |
x953 | |
C |
Glass Carving
standard input/output 2 s, 256 MB |
x584 |
第三十次……好想到紫啊好想紫55555,两个1A,14min,然后我看Standing的时候你们造么! 28名啊!!!
然后被C骗住了,我以为是zkw线段树……居然是考察数据结构set的问题……
然后……Failed System Test…… 原因?
A. Playing with Paper
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm ?×? bmm sheet of paper (a?>?b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.
After making a paper ship from the square piece, Vasya looked on the remaining (a?-?b) mm ?×? b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.
Can you determine how many ships Vasya will make during the lesson?
Input
The first line of the input contains two integers a, b (1?≤?b?a?≤?1012) — the sizes of the original sheet of paper.
Output
Print a single integer — the number of ships that Vasya will make.
Sample test(s)
input
2 1
output
2
input
10 7
output
6
input
1000000000000 1
output
1000000000000
Note
Pictures to the first and second sample test.
说一张长方形的纸~,每次都以较短边为边长裁一个正方形下来折个纸船,问长宽已知的长方形纸能折多少个纸船。
我想说……做题的时候有这个图么!!!
每次如果裁剪的效果没有达到a的剩余部分
其实看到这个图大家应该就立马懂了,每次不要一裁裁一个正方形,咱们要裁一串,就是 a/b 个。
Code:
#include#include #include #include #include #include #include #include using namespace std; #define Max(a,b) ((a)>(b)?(a):(b)) #define Min(a,b) ((a) b; } int main() { long long a=0,b=0,c=0,t=0; cin>>a>>b; while(a!=b) { if(a%b) { c+=(a/b); a=a%b; t=a; a=b; b=t; } else { c+=(a/b); a=b; } } cout
B. Error Correct System
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about theHamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in stringS, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
Input
The first line contains integer n (1?≤?n?≤?200?000) — the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
Output
In the first line, print number x — the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1?≤?i,?j?≤?n, i?≠?j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
Sample test(s)
input
9 pergament permanent
output
1 4 6
input
6 wookie cookie
output
1 -1 -1
input
4 petr egor
output
2 1 2
input
6 double bundle
output
2 4 1
Note
In the second test it is acceptable to print i?=?2, j?=?3.
所谓海明距离,就是字符串s和字符串t字符不同的位置个数,比如acm和acg,有一个字符不同,所以是1.
题目问,如果最多允许把s中的两个不同位置的字符调换位置,那么调换后(也可以不调换)海明距离最小是多少。
假设原先海明距离是k,不调换肯定依然是k,调换的话如果要比k小只有2种情况:
1)[s]A [t]B 和某处的[s]B [t]A 调换位置,那么有两个不同处被解决了,即海明距离小了2个,最小为k-2.
2)[s]A [t]B 和某处的[s]B [t]C 调换位置,或
[s]A [t]B 和某处的[s]C [t]A 调换位置, 那么有一个不同处被解决了,即海明距离小了2个,最小为k-1.
那么,该怎么写呢?
由于字符的不同处可多可少,感觉如果全都消耗时间空间比较浪费所以我使用的是map,有的就放进来,读的过程中还可以同时把海明距离数出来,这是O(n)。
用map找由于其本质是红黑树,所以是在O(lgn)的时间内寻找到,综合来看最坏情况也是nlgn,可行。
Code:
#include
上一篇: python程序怎么变成软件
下一篇: python里break怎么用
推荐阅读
-
第二十次codeforces竞技结束 #276 Div 2
-
第一次codeforces竞技结束 #238 Div 2
-
第二十次codeforces竞技结束 #276 Div 2
-
第七次codeforces竞技结束 #258 Div 2
-
第一次codeforces竞技结束 #238 Div 2
-
第二十七次codeforces竞技结束 #288 Div 2
-
第七次codeforces竞技结束 #258 Div 2
-
第二十次codeforces竞技结束 #276 Div 2_html/css_WEB-ITnose
-
第二十八次codeforces竞技结束 #291 Div 2
-
第三十五次codeforces竞技结束 #483 Div 2