Timus : 1131 (Copying)



// http://acm.timus.ru/problem.aspx?space=1&num=1131
// runtime: 0.015s
// tag: math


#include <stdio.h>
#include <math.h>

int main ()
{
	int n, k; scanf ("%d %d", &n, &k);

	int hrs = 0;
	int activePc = 1;

	while ( true ) {
		if ( activePc <= k ) activePc *= 2;
		hrs++;

		if ( activePc >= n ) break;

		if ( k < activePc ) {
			hrs += (int) ceil ((n - activePc) / (double) k);
			break;
		}
	}

	printf ("%d\n", hrs);

	return 0;
}
Advertisements

Timus: 1225 (Flags)



// http://acm.timus.ru/problem.aspx?space=1&num=1225
// Runtime: 0.031s
// Tag: Dp
// How many ways u can make a binary string (0/1) of length n, where two '1' can't be adjacent 

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#include <ctime>

#define Inf 2147483647
#define Pi acos(-1.0)
#define N 1000000
#define LL long long

#define F(i, a, b) for( int i = (a); i < (b); i++ )
#define Fs(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fe(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define Pr(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) cout << *it << " "; cout << endl;
#define Set(a, s) memset(a, s, sizeof (a))
#define Rd(r) freopen(r, "r", stdin)
#define Wt(w) freopen(w, "w", stdout)

using namespace std;

int n;
LL dp [45 + 3] [2];

LL recur (int at, int pre)
{
	if ( at == n ) {
		if ( pre == 1 ) return 0;
		return 1;
	}

	if ( dp [at] [pre] != -1 ) return dp [at] [pre];

	LL c = 0;

	if ( pre != 1 ) {
		c += recur (at + 1, 1);
		c += recur (at + 1, 0);
	} else {
		c += recur (at + 1, 0);
	}

	return dp [at] [pre] = c;
}


int main ()
{
	scanf ("%d", &n);

	Set (dp, -1);
	LL p = recur (1, 0);
	printf ("%lld\n", p * 2);

	return 0;
}

// @END_OF_SOURCE_CODE

Timus: 1011 (Conductors)



// http://acm.timus.ru/problem.aspx?space=1&num=1011
// Runtime: 0.015s
// Tag: Math, Eps

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#include <ctime>

#define Inf 2147483647
#define Pi acos(-1.0)
#define N 1000000
#define LL long long

#define F(i, a, b) for( int i = (a); i < (b); i++ )
#define Fs(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fe(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define Pr(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) cout << *it << " "; cout << endl;
#define Set(a, s) memset(a, s, sizeof (a))
#define Rd(r) freopen(r, "r", stdin)
#define Wt(w) freopen(w, "w", stdout)

using namespace std;


int main ()
{
	double p, q; scanf ("%lf %lf", &p, &q);

	double people = 1;

	while ( true ) {
		double a = people * p / 100;
		double b = people * q / 100;
		a += 1e-6;
		b -= 1e-6;

		int t1 = ceil (a);
		int t2 = floor (b);

		if ( t1 == t2 ) { printf ("%0.lf\n", people); break; }
		people++;
	}

	return 0;
}

// @END_OF_SOURCE_CODE

Timus: 1349 (Farm)



// http://acm.timus.ru/problem.aspx?space=1&num=1349
// Runtime: 0.015s
// Tag: Fermat's last theorem

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#include <ctime>

#define Inf 2147483647
#define Pi acos(-1.0)
#define N 1000000
#define LL long long

#define F(i, a, b) for( int i = (a); i < (b); i++ )
#define Fs(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fe(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define Pr(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) cout << *it << " "; cout << endl;
#define Set(a, s) memset(a, s, sizeof (a))
#define Rd(r) freopen(r, "r", stdin)
#define Wt(w) freopen(w, "w", stdout)

using namespace std;


int main ()
{
	int n; scanf ("%d", &n);

	switch (n) {
	case 1: printf ("1 2 3\n"); break;
	case 2: printf ("3 4 5\n"); break;
	default: printf ("-1\n");
	}

	return 0;
}

// @END_OF_SOURCE_CODE

Timus : 1052 (Rabbit Hunt)



// http://acm.timus.ru/problem.aspx?space=1&num=1052
// Runtime: 0.031s
// Memory: 112 KB
// Tag: Geometry
// Hints: if area of triangle ABC is zero, then points A, B, C are co-linear. 

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL long long

#define For(i, a, b) for( int i = (a); i < (b); i++ )
#define Fors(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fore(it, x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define Set(a, s) memset(a, s, sizeof (a))
#define Read(r) freopen(r, "r", stdin)
#define Write(w) freopen(w, "w", stdout)

int dr [] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dc [] = {0, 1, 1, 1, 0, -1, -1, -1};

using namespace std;

int x [200 + 5];
int y [200 + 5];

int triangleArea (int a, int b, int c) {
    return x [a] * (y [b] - y [c]) + x [b] * (y [c] - y [a]) + x [c] * (y [a] - y [b]);
}

int main ()
{
    int n; scanf ("%d", &n);

    for ( int i = 0; i < n; i++ ) scanf ("%d %d", &x [i], &y [i]);

    int cnt;
    int maxi = INF_MIN;

    for ( int i = 0; i < n; i++ ) {
        for ( int j = i + 1; j < n; j++ ) {
            cnt = 2;
            for ( int k = j + 1; k < n; k++ ) {
                if ( triangleArea (i, j, k) == 0 ) cnt++;
            }
            if ( cnt > maxi ) maxi = cnt;
        }
    }

    printf ("%d\n", maxi);

	return 0;
}

// @END_OF_SOURCE_CODE

Timus : 1100 (Final Standings)



// http://acm.timus.ru/problem.aspx?space=1&num=1100
// Tag: Stable sort 

#include <cstdio>
#include <algorithm>

using namespace std;

struct node {
    int id;
    int solve;
} a [10000000 + 10];

bool cmp (node p, node q)
{
    if ( p.solve > q.solve ) return true;
    return false;
}

int main ()
{
    int n; scanf ("%d", &n);

    for ( int i = 0; i < n; i++ ) scanf ("%d %d", &a [i].id, &a [i].solve);

    stable_sort (a, a + n, cmp);

    for ( int i = 0; i < n; i++ ) printf ("%d %d\n", a [i].id, a [i].solve);

    return 0;
}

Timus : 1327 (Fuses)



// http://acm.timus.ru/problem.aspx?space=1&amp;num=1327
// Tag: adhoc, simulation

#include <stdio.h>

int main ()
{
    int a, b; scanf ("%d %d", &a, &b);
    int cnt = 0;

    for ( int i = a; i <= b; i++ ) if ( i % 2 == 1 ) cnt++;

    printf ("%d\n", cnt);

    return 0;
}