• hdu 4655 Cut Pieces


    这个解题报告讲的很详细了!!!

    代码如下:

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<algorithm>
     4 #include<iomanip>
     5 #include<cmath>
     6 #include<cstring>
     7 #include<vector>
     8 #define ll __int64
     9 #define pi acos(-1.0)
    10 #define MAX 1000010
    11 #define mod 1000000007
    12 using namespace std;
    13 int an[MAX];
    14 ll s,ans,temp;
    15 ll pows(ll a,ll b){
    16     ll ans=1;
    17     while(b){
    18         if(b&1) ans=(ans*a)%mod;
    19         b>>=1;
    20         a=(a*a)%mod;
    21     }
    22     return ans;
    23 }
    24 int main(){
    25     int t,i,j,n;
    26     cin>>t;
    27     while(t--){
    28         cin>>n;
    29         s=1;
    30         for(i=0;i<n;i++){
    31             scanf("%d",&an[i]);
    32             s*=an[i];
    33             s%=mod;
    34         }
    35         sort(an,an+n);
    36         j=n-1;
    37         ans=n*s%mod;
    38         temp=0;
    39         for(i=n-1;i>=0;i--){
    40             if(!j) break;
    41             ll tt=s*pows(an[i],mod-2)%mod;
    42             temp=(tt+temp)%mod;
    43             j--;
    44             if(!j) break;
    45             temp=(tt+temp)%mod;
    46             j--;
    47             if(!j) break;
    48         }
    49         printf("%I64d
    ",((ans-temp)%mod+mod)%mod);
    50     }
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    站立会议第七天
    站立会议第六天
    站立会议第五天
    站立会议第四天
    inotify简题
    搭建企业版yum仓
    ssh及ssh-key
    shell变量
    如何下载scp、wget、inotify及如何偷包
    rsync
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3249656.html
Copyright © 2020-2023  润新知