• 【AtCoder】ARC070


    ARC070

    C - Go Home

    题目大意:一只袋鼠第i秒可以向左或向右跳i步或者不跳,问从0跳到x的最小时间

    就是1,2,3,4...k总和超过x的最小的k,因为如果超过了x的那部分需要减掉的那步我不跳即可

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define eps 1e-10
    #define MAXN 200005
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    typedef unsigned int u32;
    typedef double db;
    template<class T>
    void read(T &res) {
        res = 0;T f = 1;char c = getchar();
        while(c < '0' || c > '9') {
        	if(c == '-') f = -1;
        	c = getchar();
        }
        while(c >= '0' && c <= '9') {
        	res = res * 10 +c - '0';
        	c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) {
        	out(x / 10);
        }
        putchar('0' + x % 10);
    }
    int X;
    
    void Solve() {
        read(X);
        int r = 0;
        for(int i = 1 ; i <= 100000 ; ++i) {
            r += i;
            if(r >= X) {
                out(i);enter;return;
            }
        }
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    

    D - No Need

    大意:若一个数在任意总和大于等于K的子集内被删掉后,该子集的和仍然大于等于K,认为这个数不必要,求不必要的数的个数

    发现如果小于这个数的某值是必要的,这个数也一定是必要的,我们做一个背包,如果存在一个值小于K加上这个数是大于等于K的,那么这个数就是必要的,比最小的必要的数还要小的数都是不必要的

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define eps 1e-10
    #define MAXN 200005
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    typedef unsigned int u32;
    typedef double db;
    template<class T>
    void read(T &res) {
        res = 0;T f = 1;char c = getchar();
        while(c < '0' || c > '9') {
        	if(c == '-') f = -1;
        	c = getchar();
        }
        while(c >= '0' && c <= '9') {
        	res = res * 10 +c - '0';
        	c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) {
        	out(x / 10);
        }
        putchar('0' + x % 10);
    }
    int N,K,f[MAXN];
    int a[MAXN];
    void Solve() {
        read(N);read(K);
        for(int i = 1 ; i <= N ; ++i) {
            read(a[i]);
        }
        sort(a + 1,a + N + 1);
        f[0] = 1;
        int ans = N;
        for(int i = N ; i >= 1 ; --i) {
            for(int j = K - 1 ; j >= 0 ; --j) {
                if(f[j] && a[i] + j >= K) ans = min(i - 1,ans);
                if(j >= a[i]) f[j] |= f[j - a[i]];
            }
        }
        out(ans);enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    

    E - NarrowRectangles

    大意:每段长度为1的纵坐标有一个线段,初始坐标(l[i],r[i]),线段可以移动,要求相邻两个线段之间有交集,可以在端点,求最小移动距离和

    (dp[i][x])是第i条线段左边的点在x的最小花费,这个函数是一个凹(数学老师读音:wa)函数,每个拐点斜率单调递增1,最左的斜率是-i - 1

    每次相当于一个绝对值函数累加上,上一次的函数变成,左边i个点向左移动(r[i] - l[i]),右边i个点向右移动(r[i - 1] - l[i - 1])

    可以用set维护,然后两个新的拐点都是l[i]

    维护函数最小值即可

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define eps 1e-10
    #define MAXN 200005
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    typedef unsigned int u32;
    typedef double db;
    template<class T>
    void read(T &res) {
        res = 0;T f = 1;char c = getchar();
        while(c < '0' || c > '9') {
        	if(c == '-') f = -1;
        	c = getchar();
        }
        while(c >= '0' && c <= '9') {
        	res = res * 10 +c - '0';
        	c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) {
        	out(x / 10);
        }
        putchar('0' + x % 10);
    }
    int N;
    int64 l[MAXN],r[MAXN];
    multiset<int64> Lb,Rb;
    int64 c,d[2];
    void Solve() {
        read(N);
        for(int i = 1 ; i <= N ; ++i) {
            read(l[i]);read(r[i]);
        }
        Lb.insert(l[1]);Rb.insert(l[1]);c = 0;
        for(int i = 2 ; i <= N ; ++i) {
            d[0] -= r[i] - l[i];d[1] += r[i - 1] - l[i - 1];
            int64 a = *(--Lb.end()) + d[0],b = *(Rb.begin()) + d[1];
            if(l[i] < a) {
                c += abs(a - l[i]);
                Lb.erase(Lb.find(a - d[0]));Rb.insert(a - d[1]);
                Lb.insert(l[i] - d[0]);Lb.insert(l[i] - d[0]);
            }
            else if(l[i] > b){
                c += abs(b - l[i]);
                Rb.erase(Rb.find(b - d[1]));Lb.insert(b - d[0]);
                Rb.insert(l[i] - d[1]);Rb.insert(l[i] - d[1]);
            }
            else {
                Lb.insert(l[i] - d[0]);Rb.insert(l[i] - d[1]);
            }
        }
        out(c);enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    

    F - HonestOrUnkind

    如果(A <= B),从B中选A个人装成互相都是诚实的人,那么不可能分辨出来

    然后如果(A > B),如果有一个p认为q是unkind,那么p和q至少有一个unkind,同时忽略p,q,那么剩下的仍然honest大于unkind

    用个栈,问栈顶新加的点是不是unkind,如果是unkind,那么两个一起删除,最后栈顶剩下的点一定是honest,因为栈中至少有一个honest,两两之间回答都是1,一直指向栈顶都是honest

    问那个honest的人所有人的身份即可

    #include <bits/stdc++.h>
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define space putchar(' ')
    #define enter putchar('
    ')
    #define eps 1e-10
    #define MAXN 200005
    //#define ivorysi
    using namespace std;
    typedef long long int64;
    typedef unsigned int u32;
    typedef double db;
    template<class T>
    void read(T &res) {
        res = 0;T f = 1;char c = getchar();
        while(c < '0' || c > '9') {
        	if(c == '-') f = -1;
        	c = getchar();
        }
        while(c >= '0' && c <= '9') {
        	res = res * 10 +c - '0';
        	c = getchar();
        }
        res *= f;
    }
    template<class T>
    void out(T x) {
        if(x < 0) {x = -x;putchar('-');}
        if(x >= 10) {
        	out(x / 10);
        }
        putchar('0' + x % 10);
    }
    bool Query(int a,int b) {
        putchar('?');space;out(a);space;out(b);enter;
        fflush(stdout);
        char s[5];
        scanf("%s",s + 1);
        if(s[1] == 'Y') return 1;
        else return 0;
    }
    int sta[MAXN],top,A,B;
    int ans[MAXN];
    void Solve() {
        read(A);read(B);
        if(A <= B) {puts("Impossible");}
        else {
            for(int i = 0 ; i < A + B ; ++i) {
                if(!top) sta[++top] = i;
                else {
                    if(!Query(sta[top],i)) --top;
                    else sta[++top] = i;
                }
            }
            int h = sta[top];
    
            for(int i = 0 ; i < A + B ; ++i) {
                if(Query(h,i)) ans[i] = 1;
                else ans[i] = 0;
            }
            putchar('!');space;
            for(int i = 0 ; i < A + B ; ++i) {
                out(ans[i]);
            }
            enter;
        }
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    
  • 相关阅读:
    sql 读取txt 文件内容,并写入sql的方法
    Thread.Mutex 互斥体
    SQL语句创建登录名,数据库用户,数据库角色及分配权限:
    倾国倾城 歌词
    LINUX下c/c++的学习(4)linux file and direction(stat fstat lstat access umask chmod ...)
    飞蛾扑火
    生成验证码点击可刷新
    C#项目调用非托管代码函数的方法
    【学习】数据库事务
    如何判断数据库是否存在
  • 原文地址:https://www.cnblogs.com/ivorysi/p/10802912.html
Copyright © 2020-2023  润新知