TJU : 1527 (Euchre Results)



// http://acm.tju.edu.cn/toj/showp1527.html
// Tag: Adhoc

#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int main ()
{
    int a [6];

    while ( true ) {
        int sum = 0;

        for ( int i = 0; i < 6; i++ ) {
            scanf ("%d", &a [i]);
            sum += a [i];
        }

        if (sum == 0) break;

        int totalGame = a [0] + a [1] + a [2] + a [3];
        int annaWin = totalGame - (a [0] + a [2] + a [4]);
        int annaLoose = totalGame - (a [1] + a [3] + a [5]);

        printf ("Anna's won-loss record is %d-%d.\n", annaWin, annaLoose);
    }

    return 0;
}
Advertisements

TJU : 1856 (Anagrammatic Distance)



// http://acm.tju.edu.cn/toj/showp1856.html
// Tag: Adhoc

#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int main ()
{
    int testCase; scanf ("%d", &testCase);
    int cases = 0;
    getchar ();
    int freq [26 + 3];

    while ( testCase-- ) {
        char a [100], b [100];
        gets (a);
        gets (b);

        memset (freq, 0, sizeof freq);

        for ( int i = 0; a [i]; i++ ) freq [a [i] - 'a']++;
        for ( int i = 0; b [i]; i++ ) freq [b [i] - 'a']--;

        int cnt = 0;
        for ( int i = 0; i < 26; i++ ) cnt += abs (freq [i]);

        printf ("Case #%d:  %d\n", ++cases, cnt);
    }

    return 0;
}

TJU : 1935 (Symmetric Order)



// http://acm.tju.edu.cn/toj/showp1935.html

// @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)

using namespace std;

char a [15 + 3] [25 + 3];

int main ()
{
    int n;
    int cases = 0;

    while ( scanf ("%d", &n) && n ) {
        for ( int i = 0; i < n; i++ ) scanf ("%s", a [i]);

        printf ("SET %d\n", ++cases);

        for ( int i = 0; i < n; i += 2 ) printf ("%s\n", a [i]);

        if ( n % 2 ) n--;

        for ( int i = n - 1; i >= 0; i -= 2 ) printf ("%s\n", a [i]);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

TJU : 3040 (Hide That Number)



// http://acm.tju.edu.cn/toj/showp3040.html
// Runtime: 0'00.08"
// Memory: 3156K

// @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 INT_MAX 2147483647
#define INT_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 Forv(i, sz) for ( size_t i = 0; i < sz.size (); i++ )
#define Set(a, s) memset (a, s, sizeof (a))

using namespace std;

char a [N + 10];
char res [N + 10];

int main ()
{
    int cases = 0;

    while ( scanf ("%s", a) && strcmp (a, "0") ) {
        int len = strlen (a);

        reverse (a, a + len);

        res [0] = a [0];
        int tmp = res [0] - '0';

        for ( int i = 1; i < len; i++ ) {
            int diff = (a [i] - '0') - tmp;
            if ( diff < 0 ) {
                res [i] = (10 + diff) + '0';
                tmp = (res [i] - '0') + 1;

            }
            else {
                res [i] = diff + '0';
				tmp = res [i] - '0';
            }
        }

        res [len] = 0;

        reverse (res, res + len);

        if ( res [0] != '0' ) printf ("%d. %s\n", ++cases, res);
		else printf ("%d. IMPOSSIBLE\n", ++cases);
    }

	return 0;
}

// @END_OF_SOURCE_CODE

TJU : 3506 (Euler Function)


শান্ত ভাই অনেক পেইন দিয়া প্রবলেমটা সলভ করাইলেন 😦

হিন্টস্ দিতে চায় না .. আমি এত করে বললাম .. তাও দেয় না 😦

বলসি, আর ডিস্টার্ব করবো না (ছাইরা দে মা কাইন্দা বাচি) .. তাও কাজ হইল না 😦

বিরাট দুঃখ পাইলাম 😦

তবে প্রবলেমটা নিজে চিন্তা করে সলভ করতে পেরে আমি খুশি 🙂


// http://acm.tju.edu.cn/toj/showp3506.html
// Tag : sieve, prime factor, co-prime, bigmod

// @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 INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL long long
using namespace std;

bool mark [N];
vector <int> primeList;
vector <int> primeFactors;

void sieve ()
{
    memset (mark, true, sizeof (mark));

    mark [0] = mark [1] = false;

    for ( int i = 4; i < N; i += 2 ) mark [i] = false;

    for ( int i = 3; i * i <= N; i += 2 ) {
        if ( mark [i] ) {
            for ( int j = i * i; j < N; j += 2 * i ) mark [j] = false;
        }
    }

    primeList.clear ();
    primeList.push_back (2);

    for ( int i = 3; i < N; i += 2 ) {
        if ( mark [i] ) primeList.push_back (i);
    }

    //printf ("%d\n", primeList.size ());
}

void findPrimeFactors (int n)
{
    int index = 0;
    int tmp = n;
    primeFactors.clear ();

    while ( primeList [index] * primeList [index] <= n ) {
        while ( tmp % primeList [index] == 0 ) {
            tmp /= primeList [index];
            primeFactors.push_back (primeList [index]);
        }
        index++;
    }

    if ( tmp > 1 )
        primeFactors.push_back (tmp);
}

LL p2 (LL p)
{
    return p * p;
}

LL bigMod (LL b, LL p, LL m)
{
    if ( p == 0 ) return 1;
    if ( p % 2 == 0 ) return p2 (bigMod(b, p / 2, m)) % m;
    return ( (b % m) * (bigMod(b, p - 1, m) % m) ) % m;
}

int main ()
{
    sieve ();

    int n, m;

    while ( scanf ("%d %d", &n, &m) ) {
        if ( n == 0 && m == 0 ) break;

        findPrimeFactors (n);

        vector <int>::iterator it;
        it = unique ( primeFactors.begin (), primeFactors.end () );
        primeFactors.resize (it - primeFactors.begin () );

        int tmp = n;

        for ( size_t i = 0; i < primeFactors.size (); i++ )
            tmp /= primeFactors [i];

        LL res = bigMod (n, m - 1, 201004);

        res *= tmp;

        for ( size_t i = 0; i < primeFactors.size (); i++ ) {
            res *= (primeFactors [i] - 1);
            res %= 201004;
        }

        cout << res << endl;
    }

	return 0;
}

// @END_OF_SOURCE_CODE

TJU : 3513 (Triangle)



// http://acm.tju.edu.cn/toj/showp3513.html
// Tag: geometry 

// Link :
// Runtime : 0.00s
// Memory : 1216K
// Tag : geometry

// @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 INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;

int X1, Y1, X2, Y2, X3, Y3;
int dist1, dist2, dist3;
int iso_sca;    // 1 = iso,  2 = sca
int ac_ob_ri;   // 1 = ac,  2 = ob, 3 = ri

int p2 (int p) { return p * p; }

void isosceles_or_scalene ()
{
    dist1 = p2 (X1 - X2) + p2 (Y1 - Y2); // (X1, Y1) and (X2, Y2)
    dist2 = p2 (X2 - X3) + p2 (Y2 - Y3); // (X2, Y2) and (X3, Y3)
    dist3 = p2 (X1 - X3) + p2 (Y1 - Y3); // (X1, Y1) and (X3, Y3)

    iso_sca = 0;

    if ( dist1 == dist2 || dist1 == dist3 || dist2 == dist3 ) {
        iso_sca = 1; return;
    }
    else if ( dist1 != dist2 && dist1 != dist3 && dist2 != dist3 )
        iso_sca = 2;
}

void acute_obtuse_or_right ()
{
    double deg1 = acos ( (dist1 + dist2 - dist3) / (2.0 * sqrt (dist1) * sqrt (dist2)) );
    double deg2 = acos ( (dist3 + dist2 - dist1) / (2.0 * sqrt (dist3) * sqrt (dist2)) );
    double deg3 = acos ( (dist1 + dist3 - dist2) / (2.0 * sqrt (dist1) * sqrt (dist3)) );

    ac_ob_ri = 0;

    deg1 *= (180 / pi);
    deg2 *= (180 / pi);
    deg3 *= (180 / pi);

    if ( deg1 < 1e-6 || deg2 < 1e-6 || deg3 < 1e-6 ) ac_ob_ri = 0;
    else if ( deg1 > 90 || deg2 > 90 || deg3 > 90 ) ac_ob_ri = 2;
    else if ( deg1 < 90 && deg2 < 90 && deg3 < 90 ) ac_ob_ri = 1;
    else if ( deg1 - 90 < 1e-6 || deg2 - 90 < 1e-6 || deg3 - 90 < 1e-6 ) ac_ob_ri = 3;
}

int main ()
{
    int testCase;
    scanf ("%d", &testCase);
    int cases = 0;

    while ( testCase-- ) {
        scanf ("%d %d %d %d %d %d", &X1, &Y1, &X2, &Y2, &X3, &Y3);

        printf ("Case #%d: ", ++cases);

        isosceles_or_scalene ();

        acute_obtuse_or_right ();

        if (iso_sca && ac_ob_ri) {
            if ( iso_sca == 1 ) printf ("isosceles");
            else printf ("scalene");

            if ( ac_ob_ri == 1 ) printf (" acute");
            else if ( ac_ob_ri == 2 ) printf (" obtuse");
            else printf (" right");
        }
        else printf ("not a");

        printf (" triangle\n");

    }

	return 0;
}

// @END_OF_SOURCE_CODE

TJU : 3507 (Simple Date)



// http://acm.tju.edu.cn/toj/showp3507.html
// Tag : date

// @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 INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;

bool leap_year (int y)
{
    if ( y % 400 == 0 ) return true;
    if ( y % 100 == 0 ) return false;
    if ( y % 4 == 0 ) return true;
    return false;
}

int countDays (int y, int m, int d)
{
    int ret = 0;

    for ( int i = 1; i < y; i++ ) {
        if ( leap_year (i) ) ret += 366;
        else ret += 365;
    }

    int days_in_months [] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    for ( int i = 1; i < m; i++ )
        ret += days_in_months [i];

    ret += d;

    if ( leap_year(y) && m > 2 ) ret++;

    return ret;

}

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

    while ( testCase-- ) {
        int year, month, day;
        scanf ("%d/%d/%d", &year, &month, &day);

        int num_days_year1 = countDays (year, month, day);

        scanf ("%d/%d/%d", &year, &month, &day);

        int num_days_year2 = countDays (year, month, day);

        printf ("%d\n", abs (num_days_year1 - num_days_year2));

    }

	return 0;
}

// @END_OF_SOURCE_CODE