题意:在周长为10000的圆上等距分布着n个雕塑,现在又加入m个,现在让m+n个等距分布,那就得移动一些原有的雕塑,问你移动的最少总距离是多少。

析:首先我们可以知道,至少有一个雕塑是可以不用移动的,那么我们以那修个没有移动的雕塑为原点建立坐标。现在问题就转化为把剩下的移动到离它最近的位置(这个位置是放入m个雕塑之后的位置),那么这个距离就应该是最短的。

代码如下:

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath> using namespace std;
typedef long long LL;
const int maxn = 10000; int main(){
int n, m;
while(~scanf("%d %d", &n, &m)){
double ans = 0.0;
for(int i = 1; i < n; ++i){// 第0个是不移动的
double pos = (double)i / n * (n+m);
ans += fabs(pos - floor(pos+0.5)) / (m+n);// pos 四舍五入
}
printf("%.4lf\n", ans*10000);
}
return 0;
}

LA 3708 && POJ 3154 Graveyard (思维)的更多相关文章

  1. poj 3154 Graveyard 贪心

    //poj 3154 //sep9 #include <iostream> #include <cmath> using namespace std; double a[204 ...

  2. POJ 3154 Graveyard【多解,数论,贪心】

    Graveyard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1707   Accepted: 860   Specia ...

  3. 【贪心】【POJ3154】墓地雕塑(Graveyard, NEERC 2006, LA 3708)需要稍稍加工的(先贪心,再确保能这样贪(可行性&&如果可行必定最优&&非证明最优性)的题)(K)

    例题4  墓地雕塑(Graveyard, NEERC 2006, LA 3708) 在一个周长为10000的圆上等距分布着n个雕塑.现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周 ...

  4. UVALive.3708 Graveyard (思维题)

    UVALive.3708 Graveyard (思维题) 题意分析 这标题真悲伤,墓地. 在周长为1e4的圆周上等距分布着n个雕塑,现在要加入进来m个雕塑,最终还要使得这n+m个雕塑等距,那么原来的n ...

  5. [ACM_数学] LA 3708 Graveyard [墓地雕塑 圈上新加点 找规律]

    Description   Programming contests became so popular in the year 2397 that the governor of New Earck ...

  6. LA 3708 Graveyard(推理 参考系 中位数)

    Graveyard Programming contests became so popular in the year 2397 that the governor of New Earck -- ...

  7. LA 3708 Graveyard 墓地雕塑 NEERC 2006

    在一个周长为 10000 的圆上等距分布着 n 个雕塑.现在又有 m 个新雕塑加入(位置可以随意摆放),希望所有 n + m 个雕塑能在圆周上均匀分布.这就需要移动一些原有的雕塑.要求 n 个雕塑移动 ...

  8. LA 3708 Graveyard

    题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...

  9. POJ 3298 Antimonotonicity (思维)

    题目链接:http://poj.org/problem?id=3298 找一个最长不要求连续的子序列,如a1 > a3 < a6 > a7 ... 举个例子模拟一下差不多明白了,a[ ...

随机推荐

  1. spring cloud DashBoard

    1 依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring ...

  2. Spring,Hibernate 集成解决多hbm.xml文件繁多的方案

    开发一个大一点的项目有很多的hbm.xml文件,有时候上百个也不稀奇,如果用 <property name="mappingLocations"> <list&g ...

  3. struts2 模拟令牌机制防止表单重复提交

    web.xml: <?xml version="1.0" encoding="UTF-8"?><web-app version="3 ...

  4. ndarray

    ndarray ndarray-多维数组对象 ndarray数组分两部分 实际数据 描述数据的元数据(数据类型/维度等) ndarray所有元素类型相同,下标从0开始 import numpy as ...

  5. MongoDB 数据库命令

    数据库命令 连接成功后,默认使用test数据库 查看当前数据库名称 db 查看所有数据库名称,列出所有在物理上存在的数据库 show dbs 切换数据库,如果数据库不存在也并不创建,直到插入数据或创建 ...

  6. godaddy nginx https 配置

    一. 生成秘钥key,运行: $ openssl genrsa -des3 -out server.key 2048 1 会有两次要求输入密码,输入同一个即可 输入密码 然后你就获得了一个server ...

  7. Winsock版本的“hello world!”

    1.基于TCP协议的“hello world!” 1)服务器端:WSAStartup()->socket()->bind()->listen()->accept()->s ...

  8. SQL某时间段记录查询

    --查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: select * from info wh ...

  9. TokuMX写操作无法加锁的问题

    问题: TokuMX删除文档时,符合删除条件的文档很多,删除操作持续时间长,期间,服务写操作OPS大幅下降,同时日志log里发现大量“ Lock not granted. Try restarting ...

  10. program by the way......

    ostrich birds fruit apple constructor height weight method overload override base sub inherit extend ...