NWERC2016F - Free Weights

题目大意

自己看题吧,懒得写。。

简要题解

二分然后判断

#include <bits/stdc++.h>
using namespace std;
namespace my_header {
#define pb push_back
#define mp make_pair
#define pir pair<int, int>
#define vec vector<int>
#define pc putchar
#define clr(t) memset(t, 0, sizeof t)
#define pse(t, v) memset(t, v, sizeof t)
#define bl puts("")
#define wn(x) wr(x), bl
#define ws(x) wr(x), pc(‘ ‘)
    const int INF = 0x3f3f3f3f;
    typedef long long LL;
    typedef double DB;
    inline char gchar() {
        char ret = getchar();
        for(; (ret == ‘\n‘ || ret == ‘\r‘ || ret == ‘ ‘) && ret != EOF; ret = getchar());
        return ret; }
    template<class T> inline void fr(T &ret, char c = ‘ ‘, int flg = 1) {
        for(c = getchar(); (c < ‘0‘ || ‘9‘ < c) && c != ‘-‘; c = getchar());
        if (c == ‘-‘) { flg = -1; c = getchar(); }
        for(ret = 0; ‘0‘ <= c && c <= ‘9‘; c = getchar())
            ret = ret * 10 + c - ‘0‘;
        ret = ret * flg; }
    inline int fr() { int t; fr(t); return t; }
    template<class T> inline void fr(T&a, T&b) { fr(a), fr(b); }
    template<class T> inline void fr(T&a, T&b, T&c) { fr(a), fr(b), fr(c); }
    template<class T> inline char wr(T a, int b = 10, bool p = 1) {
        return a < 0 ? pc(‘-‘), wr(-a, b, 0) : (a == 0 ? (p ? pc(‘0‘) : p) :
            (wr(a/b, b, 0), pc(‘0‘ + a % b)));
    }
    template<class T> inline void wt(T a) { wn(a); }
    template<class T> inline void wt(T a, T b) { ws(a), wn(b); }
    template<class T> inline void wt(T a, T b, T c) { ws(a), ws(b), wn(c); }
    template<class T> inline void wt(T a, T b, T c, T d) { ws(a), ws(b), ws(c), wn(d); }
    template<class T> inline T gcd(T a, T b) {
        return b == 0 ? a : gcd(b, a % b); }
    template<class T> inline T fpw(T b, T i, T _m, T r = 1) {
        for(; i; i >>= 1, b = b * b % _m)
            if(i & 1) r = r * b % _m;
        return r; }
};
using namespace my_header;

const int MAXN = 1e6 + 100;
int a[MAXN], b[MAXN];
int n;

bool ok(int p) {
    int lsv = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] > p) {
            if (lsv != 0) {
                if (lsv != a[i])
                    return false;
                lsv = 0;
            } else
                lsv = a[i];
        }
    }
    if (lsv != 0) return false;
    lsv = 0;
    for (int i = 1; i <= n; ++i) {
        if (b[i] > p) {
            if (lsv != 0) {
                if (lsv != b[i])
                    return false;
                lsv = 0;
            } else
                lsv = b[i];
        }
    }
    return lsv == 0;
}

int main() {
#ifdef lol
    freopen("F.in", "r", stdin);
    freopen("F.out", "w", stdout);
#endif
    fr(n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &b[i]);
    int l = 0, r = 1e9 + 10;
    while (l < r) {
        int m = (l + r) >> 1;
        if (ok(m))
            r = m;
        else l = m + 1;
    }
    printf("%d\n", l);

    return 0;
}
时间: 2024-08-27 01:49:22

NWERC2016F - Free Weights的相关文章

UVA 10154:Weights and Measures

Weights and Measures 题目链接: 题意: 给出一些乌龟,每只乌龟有两个值,重量a和力量b,每只乌龟可以承受b-a的重量,求把这些乌龟竖直叠在一起最多能叠多少只乌龟. 题解: 设乌龟X和乌龟Y都是答案所求的乌龟数中的两只,且Xb>Yb,可以发现min(Xb-Xa-Ya,Yb-Ya)恒大于min(Yb-Ya-Xa,Xb-Xa),因此力量大的乌龟一定在下边,可以将乌龟按重量排序.设dp[i][j]为前 i 只乌龟叠到第 j 层所剩可利用资源的最大值即可,由于数据比较大可采用滚动数组

【BZOJ-4690】Never Wait For Weights 带权并查集

4690: Never Wait for Weights Time Limit: 15 Sec  Memory Limit: 256 MBSubmit: 88  Solved: 41[Submit][Status][Discuss] Description 在实验室中,Nathan Wada作为助手的职责是测定两个样品的重量差异.当样品的差异很小时,使用天平能比使用弹簧秤得到更精确的结果,所以他只使用天平来测得一些样品的重量差.他偶尔会被询问一些样品的重量差,而他能否回答这些问题取决于在回答相应

uva 10154 - Weights and Measures【dp】qi

题意:uva 10154 - Weights and Measures 题意:有一些乌龟有一定的体重和力量,求摞起来的最大高度.力量必须承受其上面包括自己的全部的重量. 分析:先按其能举起来的力量从小到大排序 然后定义dp[i] 表示摞起来 i 只乌龟的最小质量. 然后转移就是每次用遍历O(n)的复杂度找最小的,然后记录,保存最大值即可. AC代码: #include<iostream> #include<cstdio> #include<cstring> #inclu

codeforces 339C Xenia and Weights(dp或暴搜)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts

codeforces339C - Xenia and Weights 暴搜

题意:给你无穷多个1-10的,从 1-m不停的放到天平两端,两次连续放置要在不同的天平和放不同的重量,使得每一次放置这边的天平都比对面的重量多. 解题思路: 1)暴搜,如果估算的话还是过不了的,但实际情况比估算好太多了   62ms 1 // File Name: 339c.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月03日 星期日 16时38分23秒 4 5 #include<vector> 6 #include<list

CS231n笔记4-Data Preprocessing, Weights Initialization与Batch Normalization

Data Preprocessing, Weights Initialization与Batch Normalization Data Preprocessing Weights Initialization与Batch Normalization 数据预处理Data Preprocessing 权重初始化Weights Initialization 让权重初始化为0 0方差1e-2标准差 0方差1标准差 Xavier Initialization 再改进 批归一化Batch Normaliza

Nested weights are bad for performance

警告信息“Nested weights are bad for performance”的消除方法 原因分析:在布局进行嵌套使用时,父布局与子布局都使用了android:layout_weight,但不是必须使用时,便会出现如题所示的警告信息. 解决方法:根据实际情况,去除子布局中非必须使用的android:layout_weight. Nested weights are bad for performance

笔记:Beyond sharing weights for deep domain adaptation

Based on deep learning, instead of sharing weights across source and target domains, this work proposed a two-stream architecture where different streams operate on different domains, with an additional loss function to imply the relationships across

uva10154 - Weights and Measures(01背包)

题目:uva10154 - Weights and Measures(01背包) 题目大意:给出一些乌龟的重量和力量,问怎样将这些乌龟一只放一只背上的堆起来,要求这样序列的乌龟越多越好,并且不要超出每只乌龟的负荷. 解题思路:一开始,以为只要将乌龟的力量从大到小的排下序,然后根据力量找出最长的序列.结果发现这样的做法是不对的,因为这样你就默认了越前面的乌龟就放越底下,(但是其实是可以不用的)虽说前面的乌龟力量比较大,但是重量可能也比较大,这样承受力就会变小.后来看了大神的做法,01背包.这些乌龟