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

解题

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

魔板

进制转换

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

中位数

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

方差

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

原文地址:https://www.cnblogs.com/widsom/p/10422886.html

时间: 2024-10-05 18:43:12

EOJ Monthly 2019.2的相关文章

EOJ Monthly 2019.11 E. 数学题(莫比乌斯反演+杜教筛+拉格朗日插值)

传送门 题意: 统计\(k\)元组个数\((a_1,a_2,\cdots,a_n),1\leq a_i\leq n\)使得\(gcd(a_1,a_2,\cdots,a_k,n)=1\). 定义\(f(n,k)\)为满足要求的\(k\)元组个数,现在要求出\(\sum_{i=1}^n f(i,k),1\leq n\leq 10^9,1\leq k\leq 1000\). 思路: 首先来化简一下式子,题目要求的就是: \[ \begin{aligned} &\sum_{i=1}^n\sum_{j=1

EOJ Monthly 2019.2 E 中位数 (二分+中位数+dag上dp)

题意: 一张由 n 个点,m 条边构成的有向无环图.每个点有点权 Ai.QQ 小方想知道所有起点为 1 ,终点为 n 的路径中最大的中位数是多少. 一条路径的中位数指的是:一条路径有 n 个点,将这 n 个点的权值从小到大排序后,排在位置 ⌊n2⌋+1 上的权值. 思路(官方题解): 考虑二分答案,我们需要验证路径最大的中位数是否 ≥mid . 我们把所有的点权做 −1/1 变换,即 ≥mid 的点权变为 1 ,否则变为 −1 . 根据题面路径中位数的定义,我们可以发现,如果这条路径的中位数 ≥

EOJ Monthly 2019.2 (based on February Selection) D.进制转换

题目链接: https://acm.ecnu.edu.cn/contest/140/problem/D/ 题目: 思路: 我们知道一个数在某一个进制k下末尾零的个数x就是这个数整除kx,这题要求刚好末尾有m个0,还需要除去高位为0的情况,因此这题答案就是r / kx-(l-1)/kx-(r/kx+1-(l-1)/kx+1). 代码实现如下: 1 #include <set> 2 #include <map> 3 #include <deque> 4 #include &

EOJ Monthly 2019.2 E. 中位数 (二分+dfs)

题目传送门 题意: 在一个n个点,m条边的有向无环图中,求出所有从1到n 的路径的中位数的最大值 一条路径的中位数指的是:一条路径有 n 个点, 将这 n 个点的权值从小到大排序后,排在位置 ⌊n2⌋+1 上的权值. 思路: 看到权值为1~1e9,可以想到用二分答案,然后我们在验证的时候 可以将小于mid的边权设为-1,大于为1这样遍历一遍序列加起来的值 刚好为0 代码: #include<bits/stdc++.h> using namespace std; typedef long lon

EOJ Monthly 2019.3A

A. 钝角三角形 单点时限: 3.0 sec 内存限制: 512 MB QQ 小方以前不会判断钝角三角形,现在他会了,所以他急切的想教会你. 如果三角形的三边长分别为 a, b, c (a≤b≤c),那么当满足 a2+b2<c2 且 a+b>c 的时候,这个三角形就是一个由三边长为 a, b, c 构成的钝角三角形. 单单讲给你听肯定是不够的,为了表现自己,QQ 小方现在要考考你. 现在 QQ 小方会给你一个包含 3n 个整数的集合,分别是 {2,3,4,?3n,3n+1} ,他想让你将这个集

[EOJ Monthly] 2019.9

https://acm.ecnu.edu.cn/contest/196/ 这次是ECNU的校内选拔应该会简单一点? 下午嘉定有彩虹,在村(学)子(校)里面转了一圈,学校真大,没什么人,火烧云真美,台风 要 来 了 打开比赛,看看D:要求概率 不会是签到 看看C:这么大的模拟,不是签到 看看A:要么找规律要么SG,然后很长时间都没有人过,可能是SG,算了不管了 后来队里面有人说D是知乎原题 拿到公式开始交 逆元用费马大定理求 敲敲敲... WA WOC??为什么WA,请教了大佬队友,费马大定理会爆

EOJ Monthly 2019.11 B字母游戏

题目见:https://acm.ecnu.edu.cn/contest/231/problem/B/ 卡在第二个点和第十二个点上无数次. 和226打电话,226建议双哈希,然后一发过了....(这是226大佬的力量啊) #include<cstdio> #include<cstring> #include<algorithm> #define maxn 1005 const int mod[2]={19260817,19190504},mul[2]={29,11}; i

EOJ Monthly 2018.1 F 最小OR路径

题目链接 Description 给定一个有 \(n\) 个点和 \(m\) 条边的无向图,其中每一条边 \(e_i\) 都有一个权值记为 \(w_i\) . 对于给出的两个点 \(a\) 和 \(b\) ,求一条 \(a\) 到 \(b\) 的路径,使得路径上的边权的 \(OR\)(位或)和最小,输出这个值.(也就是说,如果将路径看做边的集合 \(\{e_1,e_2,-,e_k\}\),那么这条路径的代价为 \(w_1\ OR\ w_2\ OR\ -\ OR\ w_k\),现在求一条路径使得其

【EOJ Monthly 2018.2 (Good bye 2017)】

23333333333333333 由于情人节要回家,所以就先只放代码了. 此题是与我胖虎过不去. [E. 出老千的 xjj] #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn=3000000; #define ll long long int