hdu-4724-How Long Do You Have to Draw-贪心

题目看起来很难,其实很简单。。。。

根据题意可知,如果想连到最多的三角形,肯定是每个点都要跟其他的点相连。

然后就贪心当前连接情况下,哪一种连接方式用掉的线段最短,然后算出总和即可。

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
using namespace std;
#define maxn 110000
#define INF 99999999
double c[maxn];
double d[maxn];
double a,b;
int main()
{
    int T,cas,n,m;
    cas=0;
    scanf("%d",&T);
    while(T--)
    {
        cas++;
        scanf("%lf%lf",&a,&b);
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)scanf("%lf",&c[i]);
        for(int i=1;i<=m;i++)scanf("%lf",&d[i]);
        double ans=0.0;
        int stx,sty;
        stx=sty=1;
        double st=(a-b)*(a-b);
        ans+=sqrt((c[1]-d[1])*(c[1]-d[1])+st);
        while(1)
        {
            double x,y;
            x=y=1000000000.0;
            int leap=0;
            if(stx<n)
            {
                x=sqrt((c[stx+1]-d[sty])*(c[stx+1]-d[sty])+st);
                leap=1;
            }
            if(sty<m)
            {
                y=sqrt((c[stx]-d[sty+1])*(c[stx]-d[sty+1])+st);
                leap=1;
            }
            if(!leap)break;
            if(x<y)
            {
                stx++;
                ans+=x;
            }
            else
            {
                sty++;
                ans+=y;
            }
        }
        printf("Case #%d: %.2f\n",cas,ans);
    }
    return 0;
}

hdu-4724-How Long Do You Have to Draw-贪心

时间: 2024-11-03 21:58:08

hdu-4724-How Long Do You Have to Draw-贪心的相关文章

hdu 4723 How Long Do You Have to Draw(贪心)

How Long Do You Have to Draw Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 277    Accepted Submission(s): 110 Problem Description There are two horizontal lines on the XoY plane. One is y1 =

HDU 4004 The Frog&#39;s Games(基本算法-贪心,搜索-二分)

The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The

hdu 4544 湫湫系列故事——消灭兔子 优先队列+贪心

将兔子的血量从小到大排序,箭的威力也从小到大排序, 对于每只兔子将威力大于血量的箭加入队列,写个优先队列使得出来数位价钱最少.. #include<stdio.h> #include<queue> #include<algorithm> #include<iostream> #include<functional> using namespace std; const int maxn=100010; struct tt { int d; int

hdu 1800 Flying to the Mars(水 ,贪心)

其实就是求最大的相同的数的多少.. 我是把它当字符串输入..解决前导0的问题.. #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> using namespace std; int main() { char s[35]; int w[3500]; __int64 qq[3500]; int a; while(~scanf("%d",&a

HDU 4825 Xor Sum(经典01字典树+贪心)

Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total Submission(s): 1555    Accepted Submission(s): 657 Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Ze

hdu 4912 Paths on the tree(树链剖分+贪心)

题目链接:hdu 4912 Paths on the tree 题目大意:给定一棵树,和若干个通道,要求尽量选出多的通道,并且两两通道不想交. 解题思路:用树链剖分求LCA,然后根据通道两端节点的LCA深度排序,从深度最大优先选,判断两个节点均没被标 记即为可选通道.每次选完通道,将该通道LCA以下点全部标记. #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include

HDU 3697 Selecting courses 选课(AC代码)贪心

题意:一个学生要选课,给出一系列课程的可选时间(按分钟计),在同一时刻只能选一门课程(精确的),每隔5分钟才能选一次课,也就是说,从你第一次开始选课起,每过5分钟,要么选课,要么不选,不能隔6分钟再选.在给出的课程的事件Ai~Bi内,Bi起的那分钟是不能够选的了,就是说截止到(Bi-1)分钟59秒还能选,Bi就不能选了. 思路:由于n最大才300,那就可以使用暴力解法.开始时刻可以从0~4分钟这5个时刻开始,因为每5分钟是个周期,比如0分没选,而5分才选了,这和从5分才开始选是一样的.每隔5分钟

hdu 5773 最长递增子序列 (nlogn)+贪心

The All-purpose Zero Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 947    Accepted Submission(s): 453 Problem Description ?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] &l

HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)

Delicious Apples Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 321    Accepted Submission(s): 95 Problem Description There are  apple trees planted along a cyclic road, which is  metres lon

hdu 1052 Tian Ji -- The Horse Racing 可恶的贪心-------也算是经典贪心题吧,对于一般人来说,不看题解,应该很难做出来吧

Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20051    Accepted Submission(s): 5869 Problem Description Here is a famous story in Chinese history. "That was about