Created
May 20, 2011 23:37
-
-
Save basicxman/984014 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Original code by Code Jam user SkidanovAlexander, only comments have been added for analysis purposes. | |
| // Analysis done on 05/20/2011 | |
| #define _CRT_SECURE_NO_DEPRECATE | |
| #include <stdio.h> | |
| #include <iostream> | |
| #include <memory.h> | |
| #include <assert.h> | |
| #include <algorithm> | |
| #include <functional> | |
| #include <vector> | |
| #include <string> | |
| #include <map> | |
| #include <set> | |
| #include <deque> | |
| #include <math.h> | |
| #define fo(a,b,c) for( a = ( b ); a < ( c ); ++ a ) | |
| #define fr(a,b) fo( a, 0, ( b ) ) | |
| #define fi(a) fr( i, ( a ) ) | |
| #define fj(a) fr( j, ( a ) ) | |
| #define fk(a) fr( k, ( a ) ) | |
| #define mp make_pair | |
| #define pb push_back | |
| #define all(v) (v).begin( ), (v).end( ) | |
| #define _(a,b) memset( a, b, sizeof( a ) ) | |
| using namespace std; | |
| int ni() { int a; scanf( "%d", &a ); return a; } | |
| double nf() { double a; scanf( "%lf", &a ); return a; } | |
| char sbuf[100005]; string ns() { scanf( "%s", sbuf ); return sbuf; } | |
| long long nll() { long long a; scanf( "%lld", &a ); return a; } | |
| template <class T> void out( T a, T b ) { bool first = true; for( T i = a; i != b; ++ i ) { if( !first ) printf( " " ); first = false; cout << * i; } printf( "\n" ); } | |
| template <class T> void outl( T a, T b ) { for( T i = a; i != b; ++ i ) { cout << * i << "\n"; } } | |
| typedef long long ll; | |
| typedef vector<int> vi; | |
| typedef vector<string> vs; | |
| typedef pair<int,int> pii; | |
| typedef map<string,int> msi; | |
| int n, m; | |
| int main( ) | |
| { | |
| int i, j, k, t, tt; | |
| // Assign file input and output to STDIN and STDOUT. | |
| freopen( "input.txt", "r", stdin ); | |
| freopen( "output.txt", "w", stdout ); | |
| // Get number of cases, assign to tt | |
| scanf( "%d\n", &tt ); | |
| for( t = 1; t <= tt; ++ t ) // Case #1..x | |
| { | |
| printf( "Case #%d:", t ); // Output case number | |
| int lastP[2] = {1,1}; // Last button | |
| int lastT[2] = {0,0}; // Last number of moves | |
| // Get number of buttons to be pressed | |
| // scanf("%d") | |
| int n = ni(); | |
| int t = 0; | |
| // for(i = 0; i < n; ++i) | |
| // Go through 0...buttons to be pressed | |
| fi(n) { | |
| string s = ns(); // Get colour of robot | |
| int id = 0; if (s == "B") id = 1; // Blue = 1, Orange = 0 | |
| int q = ni(); // Get associated button number | |
| /* | |
| * t = max( | |
| * t, | |
| * abs(buttonNumber - lastP[robot]) + lastT[robot] | |
| * ) + 1 | |
| */ | |
| t = max(t, abs(q - lastP[id]) + lastT[id]) + 1; | |
| /* | |
| * Checks which takes longer, | |
| * - The last number of turns | |
| * - The button number minus the last position of the robot plus the last number of turns for the robot. | |
| * - t is shared for both robots and with the max() call it makes sure to use the higher number of turns even if a robot presses a button later | |
| */ | |
| lastP[id] = q; // Assign current position. | |
| lastT[id] = t; // Assign new number of turns | |
| } | |
| // No need to see which robot took more turns as the number of turns is shared with the larger one always picked. | |
| printf(" %d\n", t); // Print result, case number already printed. | |
| } | |
| return 0; | |
| } | |
| /**** Once again, all original code was done by SkidanovAlexander *****/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment