UCF Local Programming Contest 2015

UCF Local Programming Contest 2015

A. Find the Twins

  • 思路:水题

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int n;
int a[11];

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    while (n -- ){
        bool flag1 = false, flag2 = false;
        for (int i = 1; i <= 10; i ++ ){
            cin >> a[i];
            if (a[i] == 17)
                flag1 = true;
            if (a[i] == 18)
                flag2 = true;
        }
        for (int i = 1; i < 10; i ++ )
            cout << a[i] << " ";
        cout << a[10] << "\n";
        if (flag1 && flag2)
            cout << "both\n\n";
        else if (flag1 && !flag2)
            cout << "zack\n\n";
        else if (!flag1 && flag2)
            cout << "mack\n\n";
        else
            cout << "none\n\n";
    }
    return 0;
}

B. Medal Ranking

  • 思路:水题

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int n;
int a[7];

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    while (n -- ){
        for (int i = 1; i <= 6; i ++ )
            cin >> a[i];
        for (int i = 1; i < 6; i ++ )
            cout << a[i] << " ";
        cout << a[6] << "\n";
        bool flag1 = false, flag2 = false;
        if (a[1] + a[2] + a[3] > a[4] + a[5] + a[6])
            flag1 = true;
        if (a[1] > a[4])
            flag2 = true;
        else if (a[1] == a[4] && a[2] > a[5])
            flag2 = true;
        else if (a[1] == a[4] && a[2] == a[5] && a[3] > a[6])
            flag2 = true;
        else
            flag2 = false;
        if (flag1 && flag2)
            cout << "both\n\n";
        else if (flag1 && !flag2)
            cout << "count\n\n";
        else if (!flag1 && flag2)
            cout << "color\n\n";
        else
            cout << "none\n\n";
    }
    return 0;
}

C. Brownies vs. Candies vs. Cookies

  • 思路:水题

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int t, n, num, cnt, x;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    for (int k = 1; k <= t; k ++ ){
        cin >> n >> num >> cnt;
        cout << "Practice #" << k << ": " << n << " " << num << "\n";
        for (int i = 1; i <= cnt; i ++ ){
            cin >> x;
            if (num > x)
                num -= x;
            else{
                while (num <= x)
                    num *= 2;
                num -= x;
            }
            cout << x << " " << num << "\n";
        }
        cout << "\n";
    }
    return 0;
}

D. Lemonade Stand

  • 思路:阅读题 读完照着模拟

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int n, d, x, s, c, pl, ps, min_pl, min_ps, cnt, num, ans;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    while (n -- ){
        min_pl = 55, min_ps = 505, num = 0, ans = 0;
        cin >> d >> x >> s;
        while (d -- ){
            cnt = 0;
            cin >> c >> pl >> ps;
            if (pl < min_pl)
                min_pl = pl;
            if (ps < min_ps)
                min_ps = ps;
            while (num < c * s){
                cnt ++ ;
                num += 80;
            }
            num -= c * s;
            ans += c * x * min_pl + cnt * min_ps;
        }
        cout << ans << "\n";
    }
    return 0;
}

E. Rain Gauge

  • 思路:我是智障 wa9 很简单的二维几何题 第二个判断条件一直写错了一直没发现

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const double pi = 3.14159265358979;
const double eps = 1e-5;

int t;
double s, r, len, x, ans;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t -- ){
        cin >> s >> r;
        len = sqrt(2.0) * s / 2.0;
        if (len < r)
            ans = s * s;
        else if (r < s / 2.0)
            ans = pi * r * r;
        else{
            double delta = 4.0 * s * s - 2.0 * 4.0 * (s * s - 2.0 * r * r);
            x = (2.0 * s - sqrt(delta)) / 4.0;
            double alpha = acos((r * r + r * r - 2.0 * x * x) / (2.0 * r * r));
            double beta = pi / 2.0 - alpha;
            double a = s - 2.0 * x;
            double h = sqrt(r * r - (a / 2.0) * (a / 2.0));
            ans = 4.0 * alpha * r * r / 2.0 + 4.0 * a * h / 2.0;
        }
        cout << fixed << setprecision(2) << ans << "\n";
    }
    return 0;
}

G. Towers of Hanoi Grid

  • 思路:仔细想一下不难得出 \(d \leq n * (n - 2) + 2\)时才满足 \(ans = d * (2 * n - 2)\)

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

int t, d, n;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    for (int i = 1; i <= t; i ++ ){
        cin >> d >> n;
        cout << "Grid #" << i << ": ";
        if (d > n * (n - 2) + 2)
            cout << "impossible\n\n";
        else
            cout << d * (2 * n - 2) << "\n\n";
    }
    return 0;
}
上一篇:A . Find the Twins -UCF Local Programming Contest 2015


下一篇:How to Design Programming(文件写入)