Problems # NameAPlayingwithPaperstandardinputoutput2s, bytes, 256MBx953CGlassCarvingstandardinputoutput2s, 256MBx584 30th times ...... Think of purple, think of purple 55555, two 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 30th times ...... Think of purple, think of purple 55555, two 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 |
30th ...... Think of purple, think of purple 55555, two 1A, 14 min, then you made it when I watched the Standing! 28 !!!
Then I was cheated by C. I thought it was a zkw line segment tree ...... The problem of data structure set ......
Then ...... Failed System Test ...... Why?
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 rectangularAMm? ×?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? ×?BMm 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 between ships Vasya will make during the lesson?
Input
The first line of the input contains two integersA,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.
Say a piece of rectangular paper ~, Each time, the shorter side is used as the side length to cut down a square and fold a paper boat. Ask how many paper boats can be folded with known length and width.
I want to say ...... Is there a picture for the question !!!
If the cropping effect does not reach the remainder of
As a matter of fact, we should understand this picture immediately. Each time we don't cut a square, we need to cut a string, that is, 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 )? (A) :( B) bool cmp (const int a, const int B) {return a> B;} int main () {long a = 0, B = 0, c = 0, t = 0; cin> a> B; while (! = 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 stringsSAndTOf equal length to be "similar". After a brief search on the Internet, he learned about theHamming distance between two stringsSAndTOf the same length, which is defined as the number of positions in whichSAndTHave 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 shoshould be swapped in stringS, So that the Hamming distance between a new stringSAnd stringTWocould 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 integerN(1? ≤?N? ≤? 200? 000)-the length of stringsSAndT.
The second line contains stringS.
The third line contains stringT.
Each of the lines only contains lowercase Latin letters.
Output
In the first line, print numberX-The minimum possible Hamming distance between stringsSAndTIf you swap at most one pair of letters inS.
In the second line, either print the indexesIAndJ(1? ≤?I,?J? ≤?N,I? ?J), If reaching the minimum possible distance is possible by swapping letters on positionsIAndJ, 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
9pergamentpermanent
Output
14 6
Input
6wookiecookie
Output
1-1 -1
Input
4petregor
Output
21 2
Input
6doublebundle
Output
24 1
Note
In the second test it is acceptable to printI? =? 2,J? =? 3.
The so-called Hamming distance refers to the number of different positions of string s and string t characters, such as acm and acg. There is a character different, so it is 1.
Question: If you are allowed to change the characters at most two different positions in s, the minimum Hamming distance after replacement (or not.
Assume that the distance of the original Haiming is k, but the distance is still k if not exchanged. If the distance is smaller than k, there are only two cases:
1) if [s] A [t] B and [s] B [t] A change location at A location, two different locations are resolved, that is, the Hamming distance is 2, the minimum is the K-2.
2) [s] A [t] B and [s] B [t] C at A location change the location, or
[S] A [t] B and [s] C [t] A at A specific place are changed, so there is A difference solved, that is, there are two smaller Hamming distances, minimum is K-1.
So, how to write it?
Because the characters can be multiple or fewer in different places, I feel that if all of them are a waste of time and space, I use map, and some will be put in, in the process of reading, we can also calculate the Hamming distance, which is O (n ).
Because map is essentially a red-black tree, it is found in O (lgn) time. In summary, the worst case is nlgn, which is feasible.
Code:
# Include# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include using namespace std; typedef pair
Pcc; # define Max (a, B) (a)> (B )? (A) :( B) # define Min (a, B) (a) <(B )? (A) :( B) bool cmp (const int a, const int B) {return a> B;} map
Mpi; map
Mci, mcii; int main () {int flag = 0, x =-1, y =-1; int n = 0, cnt = 0; cin> n; string s, t; cin> s> t; mpi. clear (); mci. clear (); mcii. clear (); for (int I = 0; I
C. Glass Carving
Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard input
Output
Standard output
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangularWMm? ×?HMm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to practice the technique of carving. to do this, he makes vertical and horizontal cuts through the entire sheet. this process results in making smaller rectangular fragments of glass. leonid does not move the newly made glass fragments. in particle, a cut pides each fragment of glass that it goes through into smaller fragments.
After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.
Leonid offers to pide the labor-he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?
Input
The first line contains three integersW,?H,?N(2? ≤?W,?H? ≤? 200? 000, 1? ≤?N? ≤? 200? 000 ).
NextNLines contain the descriptions of the cuts. Each description has the formH yOrV x. In the first case Leonid makes the horizontal cut at the distanceYMillimeters (1? ≤?Y? ≤?H? -? 1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distanceX(1? ≤?X? ≤?W? -? 1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.
Output
After each cut print on a single line the area of the maximum available glass fragment in mm2.
Sample test (s)
Input
4 3 4H 2V 2V 3V 1
Output
8442
Input
7 6 5H 4V 3V 5H 2V 1
Output
28161264
Note
Picture for the first sample test:
Picture for the second sample test:
There is a large glass ~~~
Each time a knife is chopped either horizontally or vertically, do not take it away after the cutting, and the next line also needs to cut all the parts of the line.
After each cut, the area of the largest part in the current fragment is output.
The first thing you need to know is that do not compare the area of each component one by one, because each knife is vertical or horizontal, therefore, the area of each part is equal to the product of the corresponding long side line and short side line.
That is, we only need the longest line segment on the long side and the longest line segment on the short side to output their product.
Well, let's use two routines to explain how to use these three functions ~ After all, set is not that common (please ignore this sentence when using it flexibly)
// erasing from multiset#include
#include
int main (){ std::multiset
mymultiset; std::multiset
::iterator it; // insert some values: mymultiset.insert (40); // 40 for (int i=1; i<7; i++) mymultiset.insert(i*10); // 10 20 30 40 40 50 60 it=mymultiset.begin(); it++; // ^ mymultiset.erase (it); // 10 30 40 40 50 60 mymultiset.erase (40); // 10 30 50 60 it=mymultiset.find (50); mymultiset.erase ( it, mymultiset.end() ); // 10 30 std::cout << "mymultiset contains:"; for (it=mymultiset.begin(); it!=mymultiset.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0;}
// set::find#include
#include
int main (){ std::set
myset; std::set
::iterator it; // set some initial values: for (int i=1; i<=5; i++) myset.insert(i*10); // set: 10 20 30 40 50 it=myset.find(20); myset.erase (it); myset.erase (myset.find(40)); std::cout << "myset contains:"; for (it=myset.begin(); it!=myset.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0;}
// set::insert (C++98)#include
#include
int main (){ std::set
myset; std::set
::iterator it; std::pair
::iterator,bool> ret; // set some initial values: for (int i=1; i<=5; ++i) myset.insert(i*10); // set: 10 20 30 40 50 ret = myset.insert(20); // no new element inserted if (ret.second==false) it=ret.first; // "it" now points to element 20 myset.insert (it,25); // max efficiency inserting myset.insert (it,24); // max efficiency inserting myset.insert (it,26); // no max efficiency inserting int myints[]= {5,10,15}; // 10 already in set, not inserted myset.insert (myints,myints+3); std::cout << "myset contains:"; for (it=myset.begin(); it!=myset.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; return 0;}
After talking about how to use the function, let's take a look at the problem-solving Code.
Code:
#include
#include
#include
#include
#include
#include
#include
#include
#include using namespace std;typedef long long ll;#define i insertchar ch;int n,w,h,t;set
x,y,*s;set
::iterator l,r;multiset
lx,ly,*ls;int main(){cin>>w>>h>>n; x.i(0);x.i(w);y.i(0);y.i(h);lx.i(w);ly.i(h); for (int j=1; j<=n; ++j){cin>>ch>>t; if (ch=='H') {s=&y; ls=&ly;} else {s=&x; ls=&lx;}s->i(t); l=r=s->find(t); l--; r++; ls->erase(ls->find(*r-*l));ls->i(t-*l);ls->i(*r-t);cout<<(ll)*lx.rbegin() * (ll)*ly.rbegin()<