LA 3708 && POJ 3154 Graveyard (思维)

题意:在周长为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;
}
时间: 2024-08-14 05:23:22

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

poj 3154 Graveyard 贪心

//poj 3154 //sep9 #include <iostream> #include <cmath> using namespace std; double a[2048]; double b[2048]; int main() { int n,m; while(scanf("%d%d",&n,&m)==2){ for(int i=0;i<n;++i) a[i]=i*(10000.0/n); for(int i=0;i<(n+

LA 3708 Graveyard

题意:给出一个圆周,这个圆周上有n个雕塑,现在加入m个雕塑,问最小的移动距离 因为不管怎么移动,可以选择一个作为坐标原点,所以需要挪动的是n-1个 最开始不理解白书上的式子--- 后来搜题解 http://www.cnblogs.com/wuhenqs/p/3203114.html pos = i*(n + m) /n 是把这个圆周缩成周长为(n + m)的圆,然后除以n代表原来的一份有多少,再乘以份数i,得到它原来的位置 又因为圆的周长是n+m,所以现在的pos一定是整数 所以 距离 = |p

poj 2100 Graveyard Design

Graveyard Design Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 7357   Accepted: 1816 Case Time Limit: 2000MS Description King George has recently decided that he would like to have a new design for the royal graveyard. The graveyard m

poj 2100 Graveyard Design(尺取法)

Description King George has recently decided that he would like to have a new design for the royal graveyard. The graveyard must consist of several sections, each of which must be a square of graves. All sections must have different number of graves.

POJ 3298 Antimonotonicity (思维)

题目链接:http://poj.org/problem?id=3298 找一个最长不要求连续的子序列,如a1 > a3 < a6 > a7 ... 举个例子模拟一下差不多明白了,a[i - 1]与a[i]有依赖关系. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algorithm> 3 #include <iostream> 4 #include

LA 2659 &amp;&amp; poj 3076 &amp;&amp; zoj 3122 Sudoku(精确覆盖 + DLX)

题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=660 TimeLimit: 3.000 seconds A Sudoku grid is a 16 x 16 grid of cells grouped in sixteen 4 x 4 squares, where some cells are filled wit

POJ 1852 Ants 思维题 简单题

Ants Description An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ants meet they turn back and start walking in oppos

LA 7512 November 11th (思维漏洞)

题意:给定n*m个座椅,然后有b个是坏的,要做人,并且两个人不能相邻,问你最多坐多少人,最少坐多少人. 析:这个题其实并不难,只要当时一时没想清楚,结果就一直WA,就是最少的情况时,其实一个人可以占三个座位,而不是两个,就是这一点没想清楚,其他的就简单了. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream>

poj -1852 ants (思维题)

n只蚂蚁以每秒1cm的速度在长为Lcm的杆子上爬行,当蚂蚁爬到杆子的端点时就会掉落,由于杆子太细,两只蚂蚁相遇时,他们不能交错通过,只能各自反向爬回去,对于每只蚂蚁,我们知道它距离杆子左端的距离为x,但不知道它当前的朝向,请计算所有蚂蚁落下杆子所需的最短时间很最长时间. #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring&g