Reverse Rot: Difference between revisions
Jump to navigation
Jump to search
imported>Ww109 Created page with "[http://speedyguy17.info/data/mcpc/mcpc2014/rot/rot.html Original Description] == Idea == Manipulate ASCII Numbers Handle special cases by moving them to end of normal cases..." |
imported>Ww109 No edit summary |
||
Line 1: | Line 1: | ||
[http://speedyguy17.info/data/mcpc/ | [http://speedyguy17.info/data/mcpc/mcpc2013/mcpc2013/pdfs/C%20Missing%20Pages.pdf Original Description] | ||
== Idea == | == Idea == | ||
Use the symmetry of the structure: the first two pages are bundled with the last two and so on. | |||
Given an odd P, the other three pages are P + 1, N - P and N - P + 1. For an even P, the other three pages are P - 1, N - P + 1 and N - P + 2. | |||
== Code == | |||
<syntaxhighlight line lang="cpp"> | |||
/* | |||
* ===================================================================================== | |||
* Filename: MCPC2013-C.cpp | |||
* Description: Missing Pages | |||
* Compiler: g++ | |||
* ===================================================================================== | |||
*/ | |||
#include <iostream> | |||
#include <set> | |||
using namespace std; | |||
int main () { | |||
int N; | |||
cin >> N; | |||
while (N) { | |||
int P; | |||
cin >> P; | |||
set<int> ps; | |||
if (!(P % 2)) { | |||
ps.insert(P - 1); | |||
ps.insert(N - P + 1); | |||
ps.insert(N - P + 2); | |||
} else { | |||
ps.insert(P + 1); | |||
ps.insert(N - P); | |||
ps.insert(N - P + 1); | |||
} | |||
for (set<int>::iterator i = ps.begin(); i != ps.end(); i++) { | |||
if (i != ps.begin()) cout << " "; | |||
cout << *i; | |||
} | |||
cout << endl; | |||
cin >> N; | |||
} | |||
return 0; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:mcpc2013]] | |||
[[Category:ICPC Problems]] | [[Category:ICPC Problems]] | ||
[[Category:Implementation Easy]] | [[Category:Implementation Easy]] | ||
[[Category:Algorithm Easy]] | [[Category:Algorithm Easy]] |
Revision as of 17:40, 5 December 2015
Idea
Use the symmetry of the structure: the first two pages are bundled with the last two and so on.
Given an odd P, the other three pages are P + 1, N - P and N - P + 1. For an even P, the other three pages are P - 1, N - P + 1 and N - P + 2.
Code
/*
* =====================================================================================
* Filename: MCPC2013-C.cpp
* Description: Missing Pages
* Compiler: g++
* =====================================================================================
*/
#include <iostream>
#include <set>
using namespace std;
int main () {
int N;
cin >> N;
while (N) {
int P;
cin >> P;
set<int> ps;
if (!(P % 2)) {
ps.insert(P - 1);
ps.insert(N - P + 1);
ps.insert(N - P + 2);
} else {
ps.insert(P + 1);
ps.insert(N - P);
ps.insert(N - P + 1);
}
for (set<int>::iterator i = ps.begin(); i != ps.end(); i++) {
if (i != ps.begin()) cout << " ";
cout << *i;
}
cout << endl;
cin >> N;
}
return 0;
}