zoukankan      html  css  js  c++  java
  • BZOJ 3680 吊打XXX

    Description

    gty又虐了一场比赛,被虐的蒟蒻们决定吊打gty。gty见大势不好机智的分出了n个分身,但还是被人多势众的蒟蒻抓住了。蒟蒻们将
    n个gty吊在n根绳子上,每根绳子穿过天台的一个洞。这n根绳子有一个公共的绳结x。吊好gty后蒟蒻们发现由于每个gty重力不同,绳
    结x在移动。蒟蒻wangxz脑洞大开的决定计算出x最后停留处的坐标,由于他太弱了决定向你求助。
    不计摩擦,不计能量损失,由于gty足够矮所以不会掉到地上。

    Input

    输入第一行为一个正整数n(1<=n<=10000),表示gty的数目。
    接下来n行,每行三个整数xi,yi,wi,表示第i个gty的横坐标,纵坐标和重力。
    对于20%的数据,gty排列成一条直线。
    对于50%的数据,1<=n<=1000。
    对于100%的数据,1<=n<=10000,-100000<=xi,yi<=100000

    Output

    输出1行两个浮点数(保留到小数点后3位),表示最终x的横、纵坐标。

    Sample Input

    3
    0 0 1
    0 2 1
    1 1 1

    Sample Output

    0.577 1.000
     
    随机算法+物理知识。 详情见算法:
     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cmath>
     4 using namespace std;
     5 #define maxn 10010
     6 struct node
     7 {
     8     double x,y,w;
     9 }gty[maxn];
    10 int n;
    11 double nowx,nowy;
    12 inline double dis(double a,double b)
    13 {
    14     return sqrt((a*a)+(b*b));
    15 }
    16 int main()
    17 {
    18     freopen("3680.in","r",stdin);
    19     freopen("3680.out","w",stdout);
    20     scanf("%d",&n);
    21     int i;
    22     for (i = 1;i<=n;++i)
    23         scanf("%lf %lf %lf",&gty[i].x,&gty[i].y,&gty[i].w),nowx += gty[i].x,nowy += gty[i].y;
    24     nowx /= (double) n;
    25     nowy /= (double) n;
    26     double t = 10000;
    27     do
    28     {
    29         double sumx = 0,sumy = 0;
    30         for (i = 1;i<=n;++i)
    31         {
    32             double len = dis(gty[i].x-nowx,gty[i].y-nowy);
    33             sumx += gty[i].w*(gty[i].x - nowx)/len;
    34             sumy += gty[i].w*(gty[i].y - nowy)/len;
    35         }
    36         nowx += sumx*t;
    37         nowy += sumy*t;
    38         if (t > 0.5) t *= 0.5;
    39         else t *= 0.97;
    40     }
    41     while (t>0.000000001);
    42     printf("%.3lf %.3lf",nowx,nowy);
    43     fclose(stdin); fclose(stdout);
    44     return 0;
    45 }
    View Code
    高考结束,重新回归。
  • 相关阅读:
    SPOJ 694 (后缀数组) Distinct Substrings
    POJ 2774 (后缀数组 最长公共字串) Long Long Message
    POJ 3693 (后缀数组) Maximum repetition substring
    POJ 3261 (后缀数组 二分) Milk Patterns
    UVa 1149 (贪心) Bin Packing
    UVa 12206 (字符串哈希) Stammering Aliens
    UVa 11210 (DFS) Chinese Mahjong
    UVa (BFS) The Monocycle
    UVa 11624 (BFS) Fire!
    HDU 3032 (Nim博弈变形) Nim or not Nim?
  • 原文地址:https://www.cnblogs.com/mmlz/p/4207115.html
Copyright © 2011-2022 走看看