第一次做本校OJ的题,被坑的好惨啊!

题目:600.Minimum  Distance

题目大意:给定平面上3个点A、B、C,求平面上的任一顶点P,使得|PA|+2|PB|+3|PC|。

由于刚好在这之前做了一道模拟退火的“类似”题,打了一遍模拟退火,样例都过不了;

然后又“觉得”可以三分套三分,能过样例,但还是wa了,说好的简单题呢(⁄ ⁄•⁄ω⁄•⁄ ⁄)

后来,发现前两者系数和等于第三者,所以P为C点,就是最小值。证明如下:

考虑从P移到P’式子值的变化:

令$|{P}'A|-|PA| = {d}' \ \&\&\  |{P}'B| - |PB|={d}'' \ \&\&\  |{P}'C| - |PC| = d$

$\because d >  {d}' \ \&\&\  d >  {d}'' \\$

所以有,

$$\begin{aligned}
\Delta &=|{P}'A|+2|{P}'B|+3|{P}'C|-(|PA|+2|PB|+3|PC|) \\
&=(|{P}'A|-|PA|) + 2(|{P}'B| - |PB|) + 3(|{P}'C| - |PC|)\\
&=-{d}' - 2{d}'' + 3d\\
&=(d-{d}') + 2(d-{d}'')\\
&> 0 \end{aligned}$$

所以,$d$越小越好,即P与C越紧越好,即令P与C重合。

代码实现就很简单了

#include<cstdio>
#include<cmath>
#include<algorithm>
#define long double double
using namespace std; const int INF = 0x3f3f3f3f; struct Point
{
int x, y;
};
Point points[]; double dist(Point a,Point b)
{
return sqrt((a.x - b.x) * (a.x - b.x) * 1.0 + (a.y - b.y) * (a.y - b.y) * 1.0);
} int main()
{
while (scanf("%d%d%d%d%d%d", &points[].x, &points[].y, &points[].x, &points[].y, &points[].x, &points[].y) == )
{
double ans = dist(points[], points[]) + * dist(points[], points[]);
printf("%.6lf\n", ans);
}
return ;
}
 

WOJ600——水题的更多相关文章

  1. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  2. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  3. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  4. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  5. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

  6. BZOJ 1303 CQOI2009 中位数图 水题

    1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Statu ...

  7. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  8. ACM水题

    ACM小白...非常费劲儿的学习中,我觉得目前我能做出来的都可以划分在水题的范围中...不断做,不断总结,随时更新 POJ: 1004 Financial Management 求平均值 杭电OJ: ...

  9. CF451C Predict Outcome of the Game 水题

    Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...

随机推荐

  1. 什么是以太坊私钥储存(Keystore)文件

    进入keystore管理以太坊私钥的障碍很大,主要是因为以太坊客户端在直接的命令行或图形界面下隐藏了大部分的密码复杂性. 例如,用geth: $ geth account new Your new a ...

  2. JS窗口

    <SCRIPT LANGUAGE="javascript"> <!-- window.open ('page.html', 'newwindow', 'heigh ...

  3. POJ - 1459 Power Network(最大流)(模板)

    1.看了好久,囧. n个节点,np个源点,nc个汇点,m条边(对应代码中即节点u 到节点v 的最大流量为z) 求所有汇点的最大流. 2.多个源点,多个汇点的最大流. 建立一个超级源点.一个超级汇点,然 ...

  4. codeforces 689A A. Mike and Cellphone(水题)

    题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. python调用window dll和linux so例子

    #!/usr/bin/python# -*- coding: UTF-8 -*-#python dll.pyimport win32api# 打开记事本程序,在后台运行,即显示记事本程序的窗口win3 ...

  6. python名片管理系统V2

    主程序: #! /usr/bin env python3 # -*- coding: utf-8 -*- # 项目三: # 1.要求:编写一个名片管理系统,功能如下: # 用户输入相对应的指令,实现对 ...

  7. bzoj 1025: [SCOI2009]游戏【数学+dp】

    很容易发现行数就是lcm环长,也就是要求和为n的若干数lcm的个数 有结论若p1^a1+p2^a2+...+pm^am<=n,则ans=p1^a1p2^a2..*pm^am是n的一个可行答案.( ...

  8. 【转】Spring,Spring MVC及Spring Boot区别

    对于一个Java开发者来说,Spring可谓如雷贯耳,无论是Spring框架,还是Spring引领的IOC,AOP风格,都对后续Java开发产生的深远的影响,同时,Spring社区总能及时响应开发者的 ...

  9. vs2013 安装 mvc5 的方法

    工具-->NuGet程序包管理器-->程序包管理器控制台 然后 PM>Install-Package Microsoft.AspNet.Mvc -Version 5.0.0

  10. 利用爬虫将Yuan先生的博客文章爬取下来

    由于一次巧遇,我阅读了Yuan先生的一篇博客文章,感觉从Yuan先生得博客学到很多东西,很喜欢他得文章.于是我就关注了他,并且想阅读更多出自他手笔得博客文章,无奈,可能Yuan先生不想公开自己得博客吧 ...