1. 程式人生 > >18廣工新生賽

18廣工新生賽

01:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define
lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) typedef pair<int,int> pll; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const LL mod = (int)1e9+7; const int N = 1e5 + 100; int n; int main(){ int T; scanf(
"%d", &T); while(T--){ scanf("%d", &n); int f = 1, t; while(n--){ scanf("%d", &t); if(!t) f = 0; } if(f) puts("WeRide.ai"); else puts("Transform Mobility With Autonomous Driving"); } return 0; }
View Code

 

02:

由於每個數有50% += a 50% -= a所以 數的期望是不變的。

所以就求和的時候 就用前綴合就求和一下就好了。

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
int a[N];
int main(){
    int n, m, T;
    scanf("%d", &T);
    while(T--){
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; ++i)
            scanf("%d", &a[i]), a[i] += a[i-1];
        int op, l, r;
        while(m--){
            scanf("%d%d%d", &op, &l, &r);
            if(op == 2){
                printf("%d\n", a[r] - a[l-1]);
            }
        }
    }
    return 0;
}
View Code

 

03:

如果是矩形的話,那麼一定是在直徑上,然後找到一個直徑,然後就列舉可能存在的矩形,如果存在矩形,則弧長相等。

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 305;
int a[N];
int n;
int L = 0;
inline int cal(int x, int y){
    if(x > n) x -= n;
    if(y > n) y -= n;
    if(x > y) swap(x, y);
    return min(a[y]-a[x], a[x]+L-a[y]);
}
int main(){
    while(~scanf("%d", &n)){
        for(int i = 2; i <= n; ++i){
            scanf("%d", &a[i]);
            a[i] += a[i-1];
        }
        scanf("%d", &L);
        L += a[n];
        int ans = 0;
        if(L&1) {
            printf("0\n");
            continue;
        }
        for(int i = 1; i <= n; ++i){
            for(int j = i+1; j <= n; ++j){
                if(cal(i,j) != L/2) continue;
                for(int k = i+1; k < j; ++k){
                    for(int z = j+1; z < i+n; ++z){
                        int t1 = cal(i,k), t2 = cal(j,z);
                        if(t1 == t2) ans++;
                        else if(t1 < t2) break;
                    }
                }
            }
        }
        cout << ans/2 << endl;
    }
    return 0;
}
View Code

 

04:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
char s[N];
int main(){
    int n, T;
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        getchar();
        int ans = 0, len;
        while(n--){
           cin.getline(s, N);
           if(s[0] == 'i') ans += 4;
           else if(s[0] == 'b') ans += 1;
           else if(s[0] == 'l') ans += 8;
           else if(s[0] == 'd') ans += 8;
           else if(s[0] == 'c') ans += 1;
           else if(s[0] == 'f') ans += 4;
        }
        ans = (ans+1023) / 1024;
        printf("%d\n", ans);
    }
    return 0;
}
View Code

 

05:

爆搜找規律。

爆搜程式碼:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 5e5 + 100;
int sta[N];
int Max, gg;
void dfs(int b, int l, int lt, int cnt){
    if(lt == 0){
        Max = max(Max, l);
        if(gg == l){
            for(int i = 1; i < cnt; ++i)
                cout << sta[i] << ' ';
            cout << endl;
        }
    }
    for(int i = b; i <= lt; ++i){
        sta[cnt] = i;
        dfs(i+1, l*i, lt-i, cnt+1);
    }
}
int main(){
    int n;
    while(cin >> n){
        gg = -1;
        Max = 0;
        dfs(1, 1, n, 1);
        gg = Max;
        dfs(1, 1, n, 1);
    }
    return 0;
}
View Code

 

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
LL Min[N], Max[N];
vector<int> v;
void init(){
    v.pb(2); v.pb(3);
    for(int i = 6; i <= 200; ++i){
        int t = v.size();
        if(v[0] != 2 && v[t-1] == v[t-2]+1)
            ++v[t-1];
        else if(v[0] != 2){
            --v[t-1];
            v.insert(v.begin(), 2);
        }
        else {
            int f = 1;
            for(int i = t-2; i >= 0; i--){
                if(v[i]+1 != v[i+1]){
                    ++v[i];
                    f = 0;
                    break;
                }
            }
            if(f) ++v[t-1];
        }
        Min[i] = i-1;
        Max[i] = 1;
        for(int x : v){
            Max[i] *= x;
        }
    }
}
vector<int> vc;
int main(){
    int T, n;
    scanf("%d", &T);
    init();
    Min[1] = Max[1] = 1;
    Min[2] = Max[2] = 2;
    Min[3] = 2; Max[3] = 3;
    Min[4] = 3; Max[4] = 4;
    Min[5] = 4; Max[5] = 6;
    while(T--){
        scanf("%d", &n);
        printf("%lld %lld\n", Min[n], Max[n]);
    }
    return 0;
}
View Code

 

06:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
int a[N];
int main(){
    int T, n;
    scanf("%d", &T);
    while(T--){
        scanf("%d", &n);
        int ans = 1;
        for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
        int f = 1;
        for(int i = 2; i <= n; ++i){
            if(a[i] == a[i-1]+1) ++f;
            else f = 1;
            ans = max(ans, f);
        }
        printf("%d\n", ans);
    }
    return 0;
}
View Code

 

07:

由樣例分析可得就是和牆圍成半圓,這時候面積最大。

0的時候是無解

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
double pi = acos(-1);
int main(){
    int T;
    double  n;
    scanf("%d", &T);
    while(T--){
        scanf("%lf", &n);
        double ans = n*n/pi/2;
        if(abs(ans) < 1e-8) puts("Impossble");
        else printf("%.8f\n", ans);
    }
    return 0;
}
View Code

 

08:

題解:我們可以從樣例分析中發現,我們可以經過4次跳躍之後返回到原來的這個地方。

也就是說,我們每次走到一個新的位置之後,我們可以遍歷他的所有因子,再返回到這個位置,然後繼續按原來的路徑行事。

我們不用管他怎麼走,只需要明白每出現一個數會對答案產生什麼影響就好了。

最後 是 x -> -x 。

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
int vis[N];
void init(){
    for(int i = 2; i < N; ++i){
        for(int j = i+i, t = 2; j < N; j+=i, t++){
                vis[j] += t;
        }
    }
}
int main(){
    init();
    int n;
    while(~scanf("%d", &n)){
        LL sum = 0;
        for(int i = 2; i <= n; ++i){
            sum += vis[i];
        }
        printf("%lld\n", sum*4+n-1);
    }
    return 0;
}
View Code

 

09:

題目寫的是會把數修改掉。

所以我們只需要從後往前做,每次遇到新的數的時候,都判斷一下他會不會對答案產生影響。 

如果產生影響的話,那麼肯定就是 在他後面的修改 位置是在他後面的。

然後 平方和是 n*(n+1)*(n+2) / 6

這個地方會爆LL,除法不能先取模數,然後在做乘法。

模數也不是質數,所以不能求逆元。

可以用int128做,或者連續的3個數一定就有2的倍數或者3的倍數,所以也可以先除再做。

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = 123456789;
const int N = 1e5 + 100;
int T;
int a[N];
LL cal(int x){
    __int128 v = x;
    v = v * (v+1) * (v*2+1)/6;
    v %= mod;
    return v;
}
int main(){
    scanf("%d", &T);
    while(T--){
        int n, m;
        scanf("%d%d", &n, &m);
        LL ans = 0;
        for(int i = 1; i <= m; ++i)
            scanf("%d", &a[i]);
        int lat = n+1;
        for(int i = m; i >= 1; --i){
            if(lat <= a[i]) continue;
            ans += cal(lat-a[i]);
            ans %= mod;
            lat = a[i];
        }
        ans = (ans%mod)+mod;
        ans %= mod;
        printf("%lld\n", ans);
    }
    return 0;
}
View Code

 

10:

直接模擬就好了。 不會map的可以去寫一下。

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
char mp[N];
map<string, int> ms;
string str, s;
int main(){
    int n;
    ios::sync_with_stdio(false);
    cin.tie(0);
    mp['A'] = mp['B'] = mp['C'] = '2';
    mp['D'] = mp['E'] = mp['F'] = '3';
    mp['G'] = mp['H'] = mp['I'] = '4';
    mp['J'] = mp['K'] = mp['L'] = '5';
    mp['M'] = mp['N'] = mp['O'] = '6';
    mp['P'] = mp['R'] = mp['S'] = '7';
    mp['T'] = mp['U'] = mp['V'] = '8';
    mp['W'] = mp['X'] = mp['Y'] = '9';

    while(cin >> n){
        ms.clear();
        for(int i = 1; i <= n; ++i){
            cin >> str;
            s.clear();
            for(int j = 0; j < str.size(); ++j){
                if(isalpha(str[j])){
                    s.pb(mp[str[j]]);
                }
                else if(isdigit(str[j]))
                    s.pb(str[j]);
                if(s.size() == 3) s.pb('-');
            }
            ms[s]++;
        }
        int f = 0;
        //cout << "FFF" << endl;
        for(auto it = ms.begin(); it != ms.end(); ++it){
            if(it->se > 1){
                f = 1;
                cout << it->fi << " " << it->se << endl;;
            }
        }
        if(!f) puts("No duplicates.");
    }
    return 0;
}
View Code

 

11:

題意:要有半數及以上的A或者B,然後求最大。

我們把每類人都算分開,然後排序。

然後肯定是把所以的11都放進去。

然後就是把 01 和 10 配對, 配對的時候肯定就是大的先放進去。

這樣就會剩下m個01 或者是 m個10。

我們剛開始放進去k個11。

那麼我們可以從剩下的01(10)和00當中選k個,需要每次都取大的。

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
vector<int> vc[4];
bool cmp(int x, int y){
    return x > y;
}
int main(){
    int n, op, v;
    while(~scanf("%d", &n)){
        for(int i = 0; i < 4; ++i) vc[i].clear();
        for(int i = 1; i <= n; ++i){
            scanf("%d%d", &op, &v);
            if(op == 11) vc[0].pb(v);
            if(op == 10) vc[1].pb(v);
            if(op == 1) vc[2].pb(v);
            if(op == 0) vc[3].pb(v);
        }
        for(int i = 1; i < 3; ++i)
            sort(vc[i].begin(), vc[i].end(), cmp);
        int num = vc[0].size();
        LL ans = 0;
        for(int i = 0; i < vc[0].size(); ++i) ans += vc[0][i];
        int t1 = min(vc[1].size(), vc[2].size());
        for(int i = 0; i < t1; ++i){
            ans += vc[1][i] + vc[2][i];
        }
        for(int i = t1; i < vc[1].size(); ++i)
            vc[3].pb(vc[1][i]);
        for(int i = t1; i < vc[2].size(); ++i)
            vc[3].pb(vc[2][i]);
        sort(vc[3].begin(), vc[3].end(), cmp);
        for(int i = 0; i < num && i < vc[3].size(); ++i){
            ans += vc[3][i];
        }
        printf("%lld\n", ans);
    }
    return 0;
}
View Code

 

12:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
set<int> s;
int main(){
    int T;
    scanf("%d", &T);
    while(T--){
        int b;
        scanf("%d", &b);
        for(int i = 1; i <= 1000; ++i){
            int tmp = b/__gcd(b,i);
            s.insert(tmp);
        }
        cout << s.size() << endl;
        s.clear();
    }
    return 0;
}
View Code

 

13:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod =  (int)1e9+7;
const int N = 1e5 + 100;
int main(){
    int T, n;
    scanf("%d", &T);
    for(int _cas = 1; _cas <= T; _cas++){
        if(_cas>1) puts("");
        scanf("%d", &n);
        while(n!=1){
            if(n&1){
                printf("%d*3+1=%d\n",n,n*3+1);
                n = n*3 +1;
            }
            else printf("%d/2=%d\n",n,n/2), n/=2;
        }

    }
    return 0;
}
View Code