Codeforces 989D A Shade of Moonlight

A Shade of Moonlight

列列式子发现, 对于同一个云来说只有反向的云才能和它相交, 然后我们发现这个东西有单调性,然后二分就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long

using namespace std;

const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1);

int n, l, w;
vector<int> a;
vector<int> b;

bool check(int x1, int x2) {
    return abs(x1 + x2 + l) < 1LL * (x2 + l - x1) * w;
}

int main() {
    scanf("%d%d%d", &n, &l, &w);
    for(int i = 1; i <= n; i++) {
        int x, v; scanf("%d%d", &x, &v);
        if(v == 1) a.push_back(x);
        else b.push_back(x);
    }
    LL ans = 0;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(auto& x2 : b) {
        int low = 0;
        int high = lower_bound(a.begin(), a.end(), x2) - a.begin() - 1;
        int p = -1;
        while(low <= high) {
            int mid = (low + high) >> 1;
            if(check(a[mid], x2)) p = mid, low = mid + 1;
            else high = mid - 1;
        }
        ans += p + 1;
    }
    printf("%lld\n", ans);
    return 0;
}

/*
*/

原文地址:https://www.cnblogs.com/CJLHY/p/10679333.html

时间: 2024-10-04 01:20:59

Codeforces 989D A Shade of Moonlight的相关文章

D. A Shade of Moonlight

http://codeforces.com/contest/989/problem/D emm……贪心吧. 首先呢,那个月亮是一个点,并不是一个长度为1,在[-0.5,0.5]之间的线段,我被Note忽悠了 思路:确保最后一个点消失时能被风吹到原点 设下标为1的是从左往右,下标为2的是从右往左,最后一个点有方程式: s1+t=s2-t+l 得t=(s2-s1+l)/2 该点的坐标为 x=s1+t=(s2+s1+l)/2 风速最小为 wmin=x/t=(s2+s1+l)/(s2-s1+l)<=wm

[CF989D]A Shade of Moonlight:几何+二分答案+玄学的思路

题意: 一条一维数轴上,有n个左端点为xi,长度l的区间.以向右为正方向,第i个区间的移动速度为vi+w(vi=1或-1,|w|<=wmax,所有区间的w相同). 输入n,l,wmax,vi. 输出无序数对(i,j)的个数,使第i个区间和第j个区间有一个合法的w的取值,在某一时刻同时覆盖原点(不包括区间左.右边界). (n<=1e5) 思路: 因为w的取值是不定的,所以可以看成是每个区间以vi的速度运动,而原点以-w的速度运动. 很容易画出一个时间-位置图像(横轴位置,纵轴时间),其中橙色区域

CodeForces 989D

题意略. 思路: 可以看成是所有的云彩照常运动,而月亮在跑.只要两个云彩相交后,在分离前月亮能赶到,就算是符合题意的. 可以知道,两个相隔越远的相向运动地云彩是越有可能符合题意的,因为它们相遇所用时间更长,这样月亮越有可能赶到. 假设云彩1为(l1,r1) ,云彩2为(l2,r2) ,r1 < l2 ,且两个云彩相向运动,云彩长度为 l .我们令中心点p = (r1 + l2) / 2. 月亮赶到p点所需时间为runtime = p / wmax,两个云彩在相交后相离所用时间为 time = a

Codeforces Round #105 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/148 比较简单的一场,最长的一题也才写了30行多一点 A. Insomnia cure time limit per test:2 seconds memory limit per test:256 megabytes ?One dragon. Two dragon. Three dragon?, - the princess was counting. She had trouble falling asleep, and

Codeforces 148D Bag of mice (概率dp)

D. Bag of mice time limit per test:2 seconds memory limit per test:256 megabytes The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, wh

CodeForces 148D. Bag of mice(概率dp啊 )

题目链接:http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The dragon and the princess are arguing about what to do on the New Year'

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th