2020 Multi-University Training Contest 8(待补

2020 Multi-University Training Contest 8

1003 Clockwise or Counterclockwise

  • 思路:水题 矢量叉积一下即可判断

  • 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;
ll x1, y1_, x2, y2, x3, y3; 

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 >> x1 >> y1_ >> x2 >> y2 >> x3 >> y3;
        if ((x1 - x2) * (y3 - y2) - (x3 - x2) * (y1_ - y2) > 0)
            cout << "Clockwise\n";
        else
            cout << "Counterclockwise\n";
    }
    return 0;
}

1006 Fluctuation Limit

  • 思路:前后分别扫一遍 判断即可

  • 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, n, k;
int l[N], r[N];
bool flag;

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 -- ){
        flag = true;
        cin >> n >> k;
        for (int i = 1; i <= n; i ++ )
            cin >> l[i] >> r[i];
        for (int i = 2; i <= n; i ++ ){
            l[i] = max(l[i], l[i - 1] - k);
            r[i] = min(r[i], r[i - 1] + k);
        }
        for (int i = n - 1; i >= 1; i -- ){
            l[i] = max(l[i], l[i + 1] - k);
            r[i] = min(r[i], r[i + 1] + k);
        }
        for (int i = 1; i <= n; i ++ ){
            if (l[i] > r[i]){
                flag = false;
                break;
            }
        }
        if (!flag)
            cout << "NO\n";
        else{
            cout << "YES\n";
            for (int i = 1; i < n; i ++ )
                cout << l[i] << " ";
            cout << l[n] << "\n";
        }
    }
    return 0;
}

1008 Hexagon

  • 思路:规律题 画图找找规律就出来了

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

inline void calc(int x){
    if (x <= 1)
        return ;
    if (x == 2){
        cout << "345613";
        return ;
    }
    int tmp;
    tmp = x - 2;
    cout << "3";
    while (tmp -- )
        cout << "42";
    tmp = x - 2;
    cout << "4";
    while (tmp -- )
        cout << "53";
    tmp = x - 2;
    cout << "5";
    while (tmp -- )
        cout << "64";
    tmp = x - 2;
    cout << "6";
    while (tmp -- )
        cout << "15";
    tmp = x - 2;
    cout << "1";
    while (tmp -- )
        cout << "26";
    tmp = x - 3;
    cout << "23";
    while (tmp -- )
        cout << "13";
    cout << "4";
    calc(x - 2);
}

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 >> n;
        calc(n);
        cout << "\n";
    }
    return 0;
}

1009 Isomorphic Strings

  • 思路:将串s分别取因子长度 并复制一遍得到串t 跑KMP判断子串是否包含于串t即可(出题人害人不浅啊 由于先入为主的先做了F题 导致以为都是输出YES&NO wa到自闭

  • 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 = 5e6 + 10;
const int mod = 19260817;

int T, n, len, tot;
int nxt[N];
bool flag;
char s[N], t[N], tmp[N];
vector<ll> vec;

inline void get_nxt(int x){
    nxt[0] = -1;
    int j = 0, k = -1;
    while (j < x){
        if (k == -1 || tmp[j] == tmp[k]){
            j ++ , k ++ ;
            if (tmp[j] != tmp[k])
                nxt[j] = k;
            else
                nxt[j] = nxt[k];
        }
        else
            k = nxt[k];
    }
}

inline int KMP(int x){
    int i = 0, j = 0;
    get_nxt(x);
    while (i < len && j < x){
        if (j == -1 || t[i] == tmp[j])
            i ++ , j ++ ;
        else
            j = nxt[j];
    }
    if (j == x)
        return i - j + 1;
    else
        return -1;
}

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 -- ){
        flag = false;
        vec.clear();
        cin >> n >> s;
        if (n == 1){
            cout << "No\n";
            continue;
        }
        for (ll i = 1; i < n; i ++ )
            if (n % i == 0)
                vec.emplace_back(i);
        for (auto x: vec){
            tot = 0;
            len = 2 * x;
            for (int i = 0; i < x; i ++ )
                t[i] = s[i];
            for (int i = x; i < 2 * x; i ++ )
                t[i] = t[i - x];
            for (int i = 0; i < n / x; i ++ ){
                for (int j = x * i; j < x * i + x; j ++ )
                    tmp[ tot ++ ] = s[j];
                tot = 0;
                int ans = KMP(x);
                if (ans == -1){
                    tot = mod;
                    break;
                }
            }
            // cout << tot << "\n";
            if (tot != mod)
                flag = true;
        }
        if (flag)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}
posted @ 2020-08-18 00:38  Misuchii  阅读(130)  评论(0编辑  收藏  举报