zoukankan      html  css  js  c++  java
  • bzoj1011

    因为允许5%的误差。。所以把>一定长度的一段看成一段近似计算就行了。。

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<ctime>
     5 #include<cmath>
     6 #include<iostream>
     7 #include<algorithm>
     8 #include<queue>
     9 #include<stack>
    10 #include<set>
    11 #define clr(a,x) memset(a,x,sizeof(a))
    12 #define rep(i,l,r) for(int i=(l);i<(r);i++)
    13 using namespace std;
    14 typedef long long ll;
    15 typedef pair<int,int> pii;
    16 #define mkp(a,b) make_pair(a,b)
    17 int read(){
    18     int ans=0,f=1;
    19     char c=getchar();
    20     while(!isdigit(c)){
    21         if(c=='-') f=-1;
    22         c=getchar();
    23     }
    24     while(isdigit(c)){
    25         ans=ans*10+c-'0';
    26         c=getchar();
    27     }
    28     return ans*f;
    29 }
    30 const int maxn=100009;
    31 int n;
    32 ll w[maxn];
    33 double a;
    34 void solve(int k,int l,int r){
    35     double ans=0;
    36     if(r-l<=500){
    37         rep(i,l,r+1) ans+=1.0*(w[i]-w[i-1])/(k-i);
    38     }else{
    39         while(l<=r){
    40             int t=min(l+500,r);
    41             ans+=1.0*(w[t]-w[l-1])/(k-(l+t)/2);
    42             l=t+1;
    43         }
    44     }
    45     printf("%.7lf
    ",ans*(w[k]-w[k-1]));
    46 }
    47 int main(){
    48     n=read();scanf("%lf",&a);
    49     rep(i,1,n+1) w[i]=w[i-1]+read();
    50     rep(i,1,n+1) solve(i,1,floor(a*i));
    51     return 0;
    52 }
    View Code

    1011: [HNOI2008]遥远的行星

    Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special Judge
    Submit: 2872  Solved: 1034
    [Submit][Status][Discuss]

    Description

    直线上N颗行星,X=i处有行星i,行星J受到行星I的作用力,当且仅当i<=AJ.此时J受到作用力的大小为 Fi->j=Mi*Mj/(j-i) 其中A为很小的常量,故直观上说每颗行星都只受到距离遥远的行星的作用。请计算每颗行星的受力,只要结果的相对误差不超过5%即可.

    Input

    第一行两个整数N和A. 1<=N<=10^5.0.01< a < =0.35 
    接下来N行输入N个行星的质量Mi,保证0<=Mi<=10^7

    Output

    N行,依次输出各行星的受力情况

    Sample Input

    5 0.3
    3
    5
    6
    2
    4

    Sample Output

    0.000000
    0.000000
    0.000000
    1.968750
    2.976000

    HINT

    精确结果应该为0 0 0 2 3,但样例输出的结果误差不超过5%,也算对

    Source

     
    [Submit][Status][Discuss]
  • 相关阅读:
    刷题第一天各种蒙圈
    如何用MATLAB读stl并显示点云文件
    MATLA总结三
    word里如何将模板的样式(标题啊、字体啊)导入到另外的模板里
    Asp.Net跨平台:Ubuntu14.0+Mono+Jexus+Asp.Net
    Newtonsoft.Json输出Json时动态忽略属性
    Redis 系列 (一) StackExchange.Redis的使用
    jquery选择器如何获取父级元素、同级元素、子元素
    多线程的应用小结
    nginx1.18支持http2.0
  • 原文地址:https://www.cnblogs.com/chensiang/p/5010003.html
Copyright © 2011-2022 走看看