EOJ Monthly 2019.2

题解

回收卫星

EOJ Monthly 2019.2
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

int main() {
    LL l = 0, r = 2e9, m = l+r+1 >> 1;
    int f;
    while(l < r) {
        cout << 0 << " " << m << " " << 0 << " " << 0 << endl;
        cin >> f;
        if(f) l = m;
        else r = m-1;
        m = l+r+1 >> 1;
    }
    LL x1 = m;
    l = 0, r = 2e9, m = l+r+1 >> 1;
    while(l < r) {
        cout << 0 << " " << -m << " " << 0 << " " << 0 << endl;
        cin >> f;
        if(f) l = m;
        else r = m-1;
        m = l+r+1 >> 1;
    }
    LL x2 = -m;
    LL x = (x1+x2)/2;
    l = 0, r = 2e9, m = l+r+1 >> 1;
    while(l < r) {
        cout << 0 << " " << x << " " << m << " " << 0 << endl;
        cin >> f;
        if(f) l = m;
        else r = m-1;
        m = l+r+1 >> 1;
    }
    LL y1 = m;
    l = 0, r = 2e9, m = l+r+1 >> 1;
    while(l < r) {
        cout << 0 << " " << x << " " << -m << " " << 0 << endl;
        cin >> f;
        if(f) l = m;
        else r = m-1;
        m = l+r+1 >> 1;
    }
    LL y2 = -m;
    LL y = (y1+y2)/2;
    l = 0, r = 2e9, m = l+r+1 >> 1;
    while(l < r) {
        cout << 0 << " " << x << " " << y << " " << m << endl;
        cin >> f;
        if(f) l = m;
        else r = m-1;
        m = l+r+1 >> 1;
    }
    LL z1 = m;
    l = 0, r = 2e9, m = l+r+1 >> 1;
    while(l < r) {
        cout << 0 << " " << x << " " << y << " " << -m << endl;
        cin >> f;
        if(f) l = m;
        else r = m-1;
        m = l+r+1 >> 1;
    }
    LL z2 = -m;
    LL z = (z1+z2)/2;
    cout << 1 << " " << x << " " << y << " " << z << endl;
    return 0;
}
View Code

解题

EOJ Monthly 2019.2
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 1e6 + 5, M = 5e7 + 5;
char s[N];
int pos[M], m;
int main() {
    int q;
    scanf("%s", s+1);
    int n = strlen(s+1);
    scanf("%d", &q);
    while(q--) {
        scanf("%d", &m);
        int now = 0, l, r;
        for (int i = 0; i <= m; ++i) pos[i] = 0;
        int b = 1;
        for (int i = n; i >= 1; i--) {
            now = ((s[i]-'0')*b + now) % m;
            b = (b * 10) % m;
            if(now == 0) {
                l = i, r = n;
                break;
            }
            if(pos[now]) {
                l = i, r = pos[now]-1;
                break;
            }
            pos[now] = i;
        }
        printf("%d %d\n", l, r);
    }
    return 0;
}
View Code

魔板

进制转换

EOJ Monthly 2019.2
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
const LL INF = 1e18 + 1;
LL l, r;
int k, m;
LL solve(LL n) {
    LL b = 1;
    for (int i = 1; i <= m; ++i) {
        if(INF/k >= b) b *= k;
        else {
            b = INF;
            break;
        }
    }
    LL bb = 1;
    if(INF/k >= b) bb = b*k;
    else bb = INF;
    return n/b - n/bb;
}
int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
         scanf("%lld %lld %d %d", &l, &r, &k, &m);
         printf("%lld\n", solve(r) - solve(l-1));
    }
    return 0;
}
View Code

中位数

EOJ Monthly 2019.2
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 1e6 + 5;
const int INF = 0x3f3f3f3f;
vector<int> g[N];
int a[N], d[N], in[N];
int topo[N];
int n, m, u, v;
bool vis[N];
queue<int> q;
stack<int> st;
void Topo() {
    for (int i = 1; i <= n; ++i) {
        if(in[i] == 0) q.push(i);
    }
    int cnt = 0;
    while(!q.empty()) {
        int u = q.front();
        topo[++cnt] = u;
        q.pop();
        for (int v : g[u]) {
            in[v]--;
            if(in[v] == 0) q.push(v);
        }
    }
}
bool ck(int m) {
    for (int i = 1; i <= n; ++i) d[i] = -INF;
    d[1] = ((a[1] >= m)? 1 : -1);
    for (int i = 1; i <= n; ++i) {
        int u = topo[i];
        if(!vis[u]) continue;
        for (int v : g[u]) {
            d[v] = max(d[v], d[u]+((a[v] >= m)? 1 : -1));
        }
    }
    return d[n] >= 0;
}
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= m; ++i) {
        scanf("%d %d", &u, &v);
        g[u].pb(v);
        in[v]++;
    }
    Topo();
    st.push(1);
    while(!st.empty()) {
        int u = st.top();
        st.pop();
        if(vis[u]) continue;
        vis[u] = true;
        for (int v : g[u]) {
            if(!vis[v]) st.push(v);
        }
    }
    if(!vis[n]) {
        puts("-1");
        exit(0);
    }
    int l = 0, r = 1e9, mid = l+r+1 >> 1;
    while(l < r) {
        if(ck(mid)) l = mid;
        else r = mid-1;
        mid = l+r+1 >> 1;
    }
    printf("%d\n", mid);
    return 0;
}
View Code

方差

EOJ Monthly 2019.2
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const LL INF = 0x7f7f7f7f7f7f7f7f;
const int N = 1e6 + 5, M = 1e3 + 5;
int a[N], cnt[M], sum[M];
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    LL ans = INF, x = 0, y = 0;
    sort(a+1, a+1+n);
    for (int i = 1; i <= n; ++i) {
        if(i <= m) {
            x += 1LL*a[i]*a[i];
            y += a[i];
        }
        else {
            x -= 1LL*a[i-m]*a[i-m];
            x += 1LL*a[i]*a[i];
            y -= a[i-m];
            y += a[i];
        }
        if(i >= m) ans = min(ans, m*x - y*y);
    }
    printf("%lld\n", ans);
    return 0;
}
View Code

 

上一篇:ubuntu20.04.2设置配置静态ip方法


下一篇:Web自动化测试 Selenium 3/3 https的配置