zoukankan      html  css  js  c++  java
  • Trees in a Wood UVA

    太坑惹,,,没用longlong各种WA

     1 #include <iostream>
     2 #include <string.h>
     3 #include <cstdio>
     4 #include <math.h>
     5 #define SIGMA_SIZE 26
     6 #pragma warning ( disable : 4996 )
     7 
     8 using namespace std;
     9 typedef long long LL;
    10 
    11 inline int Max(int a,int b) { return a>b?a:b; }
    12 inline int Min(int a,int b) { return a>b?b:a; }
    13 const int inf = 0x3f3f3f3f;
    14 const int maxn = 2e3+5;
    15 const int maxk = 2e6+5;
    16 
    17 int gcd(int a, int b)
    18 { return b==0?a:gcd(b,a%b); }
    19 int A, B;
    20 int oula[maxn];
    21 bool g[maxn][maxn];
    22 
    23 void init()
    24 {
    25     memset( g, false, sizeof(g) );
    26     int i, j;
    27     for ( i = 0; i < maxn; i++ )
    28         oula[i] = i;
    29 
    30     for ( i = 2; i < maxn; i++ )
    31         if ( oula[i] == i )
    32             for ( j = i; j < maxn; j+=i )
    33                 oula[j] = oula[j]/i*(i-1);
    34 
    35     for( i = 1; i < maxn; i++ )
    36         for( j = 1; j < maxn; j++ )
    37             if( gcd(i,j) == 1 )
    38                 g[i][j] = true;
    39 }
    40 
    41 int main()
    42 {
    43     init();
    44     while ( ~scanf("%d%d", &A, &B)&&A&&B )
    45     {
    46         if( A > B ) swap(A,B);    
    47         double sum = 0;
    48 
    49         for ( int i = 1; i <= A; i++ )
    50         {
    51             sum += oula[i]*(B/i);
    52             int tmp = B%i;
    53             for( int j = 1; j <= tmp; j++ )
    54                 if ( g[i][j] )
    55                     sum++;
    56         }
    57         
    58         double ans = sum*2 + 2;
    59         double all = (unsigned long long)A*B*2+A+B;
    60         printf( "%.7lf
    ", ans/all );
    61     }
    62 
    63     return 0;
    64 }
  • 相关阅读:
    跟结束进程相关的那些信号
    tcpdump使用示例
    Linux在bash history当中添加timestamp
    CentOS中在/etc/rc.local添加开机自启动项启动失败
    CentOS配置通过DHCP的方式动态获取IP
    CentOS桌面安装
    MySQL二进制安装
    对okhttp参数的一些思考
    依赖倒置原则(DIP)
    Liskov替换原则(LSP)
  • 原文地址:https://www.cnblogs.com/chaoswr/p/8678553.html
Copyright © 2011-2022 走看看