2020 Multi-University Training Contest 7(待补

2020 Multi-University Training Contest 7

1007 Game

  • 思路:依次取最长边,最后只剩下起点一个点,后手可以选择先手选的所在边的另一个点,使先手败

  • 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 int N = 2010;

int t, n, tot;
bool vis[N];
ll x[N], y[N];

struct node{
    int u, v;
    ll dis;
}a[N * N];

inline bool cmp(node p, node q){
    return p.dis < q.dis;
}

ll dist(int i, int j){
    return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
}

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 -- ){
        tot = 0;
        memset(vis, false, sizeof(vis));
        cin >> n;
        for (int i = 1; i <= n; i ++ )
            cin >> x[i] >> y[i];
        for (int i = 1; i <= n; i ++ ){
            for (int j = i + 1; j <= n; j ++ ){
                a[ ++ tot ].u = i;
                a[tot].v = j;
                a[tot].dis = dist(i, j);
            }
        }
        sort(a + 1, a + tot + 1, cmp);
        for (int i = tot; i >= 1; i -- ){
            if (!vis[a[i].u] && !vis[a[i].v]){
                vis[a[i].u] = true;
                vis[a[i].v] = true;
            }
        }
        if (vis[1])
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

1009 Increasing and Decreasing

  • 思路:贪心

  • 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 int N = 1e5 + 10;

int t, pos, tot;
int ans[N];
ll n, x, y;

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 -- ){
        pos = tot = 0;
        cin >> n >> x >> y;
        if (x * y + 1 <= n || x + y - 1 > n){
            cout << "NO\n";
            continue;
        }
        cout << "YES\n";
        for (int i = 1; i <= n; i ++ ){
            if ((x - 1) * y + i < n)
                continue;
            for (int j = i; j > pos; j -- )
                ans[ ++ tot ] = j;
            pos = i;
            x -- ;
        }
        for (int i = 1; i < n; i ++ )
            cout << ans[i] << " ";
        cout << ans[n] << "\n";
    }
    return 0;
}

1010 Jogging

  • 思路:暴力bfs出所有点建无向图,答案就是“起点的度数+1”/“总度数+n”

  • 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;
}

typedef pair<ll, ll> pll;

int t, ans1, ans2;
ll x, y;
map<pll, int> vis;

inline bool bfs(ll x, ll y){
    queue<pll> q;
    q.push(make_pair(x, y));
    vis[make_pair(x, y)] = 1;
    while (!q.empty()){
        pll tmp = q.front();
        q.pop();
        if (x == y)
            return false;
        ans2 ++ ;
        for (int i = -1; i <= 1; i ++ ){
            for (int j = -1; j <= 1; j ++ ){
                if (i == 0 && j == 0)
                    continue;
                ll dx = tmp.first + i, dy = tmp.second + j;
                if (dx == dy)
                    return false;
                if (gcd(dx, dy) != 1){
                    ans2 ++ ;
                    if (!vis[make_pair(dx, dy)]){
                        vis[make_pair(dx, dy)] = 1;
                        q.push(make_pair(dx, dy));
                    }
                }
            }
        }
        if (!ans1)
            ans1 = ans2;
    }
    return true;
}

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 -- ){
        ans1 = ans2 = 0;
        vis.clear();
        cin >> x >> y;
        if (!bfs(x, y))
            cout << "0/1\n";
        else
            cout << ans1 / gcd(ans1, ans2) << "/" << ans2 / gcd(ans1, ans2) << "\n";
    }
    return 0;
}
posted @ 2020-08-15 23:22  Misuchii  阅读(169)  评论(0编辑  收藏  举报