zoj 2811 - Playground

题目:有很多个半圆环,问能不能拼成闭合图形,这里可以任意角度端点拼接。

分析:贪心。开始以为是搜索3^20觉得有点大,一看可以任意角度链接。

把range按递增序排序,每次检测前面的所有range的和是否大于当前的range;

如果前面的和大,则可以构成闭合图形;否则将它加入前面的集合,向下判断;

那么这种情况一定能取到所有的解么?

如果存在闭合图形,他的取的所有半圆构成一个集合,那么其中一定有个最大值;

而剩下的半圆的子集一定可以组成一个不小于他的图形,那么全集一定也可以;

二如果全集(不包含最大值)不能组成一个不小于最大值的图形,那子集一定不行;

所以取去掉最大值剩下的元素的全集判断,即为上面叙述的方法。

说明:大黄用的区间松弛,不过可以证明,和贪心等价。(2011-09-27 00:22)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

double hc[ 21 ];

int cmp( const void* a, const void* b )
{
    double *p = (double *)a;
    double *q = (double *)b;
    if ( *p < *q ) return -1;
    else return 1;
}

int main()
{
    int K;
    while ( scanf("%d",&K) != EOF ) {
        if ( !K ) break;
        for ( int i = 0 ; i < K ; ++ i )
            scanf("%lf",&hc[ i ]);

        qsort( hc, K, sizeof( double ), cmp );

        int flag = false;
        double sum = hc[ 0 ];
        for ( int i = 1 ; i < K ; ++ i ) {
            if ( hc[ i ]-sum < 1e-4 ) {
                flag = true;
                break;
            }
            sum += hc[ i ];
        }

        if ( flag ) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
时间: 2024-08-08 10:09:06

zoj 2811 - Playground的相关文章

zoj 2107&amp;&amp;hdu 1007最近点对问题

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1107 Quoit Design Time Limit: 5 Seconds      Memory Limit: 32768 KB Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitched at some toys, with all the toys

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n

ZOJ 2859 二维线段树

思路:自己写的第二发二维线段树1A,哈哈,看来对二维的push操作比较了解了:但是还没遇到在两个线段树中同时进行push操作的,其实这题我是想在x维和y维同时进行push操作的,但是想了好久不会,然后看到这题又给出10秒,然后想想在x维线段直接单点查询肯定也过了,然后在第二维就只有pushup操作,在第一维线段树没有pushup操作.要是在第一维也有pushup操作的话,那就不用单点查询那么慢了.不过也A了,想找题即在二维同时进行pushup和pushdown操作的. #include<iost

ZOJ 2588

求一个无向图的桥(可能存在重边),输出割边的数目,并按顺序输出割边的序号(输入的顺序). 由于内存的限制 , 无法使用邻接矩阵 , 只能用邻接表了 . 第一次用了邻接表,超内存了: 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <string.h> 5 using namespace std; 6 const int N=10002; 7 const i

ZOJ 2587 Unique Attack 判断最小割是否唯一

很裸的判断最小割是否唯一.判断方法是先做一遍最大流求最小割,然后从源点和汇点分别遍历所有能够到达的点,看是否覆盖了所有的点,如果覆盖了所有的点,那就是唯一的,否则就是不唯一的. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostr