【Codevs3151】交通管制I

Position:


List

Description

建设公路

A城是一个刚刚建立的城市,一共有n个区,其中每个区之间都要建设k个高速公路。由于刚刚建设完成,A城的管理者小Z还没建设高速公路。于是,他向你请教:他一共要建多少座高速公路?

Input

共两行

第一行N

第二行K

Output

共一行,高速公路的条数。

Sample Input

10

1

Sample Output

55

HINT

30%的数据保证1≤n≤10,1≤k≤5

70%的数据保证1≤n≤100,1≤k≤70

100%的数据保证0≤n≤10^9,0≤k≤10^9,(待续…………)

Solution

注意自己到自己也要修,可以连向自己

一共的边n+(n-1)+n-2+...+3+2+1

ans:n×(n+1)/2*k,高精度上吧。。

Code

// <3151.cpp> - Sun Oct 16 20:42:18 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=100010;
const int MAXM=100010;
inline int gi() {
    register int w=0,q=0;register char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')q=1,ch=getchar();
    while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
    return q?-w:w;
}
const int _bod_=10000;
struct BN{
    static const int N=1010;int a[N];
    BN(){memset(a,0,sizeof(a));}
    int& operator [](int n){return a[n];}
    BN operator =(int n){
         memset(a,0,sizeof(a));
         a[1]=n;if(a[1])a[0]=1;
         while(a[a[0]]>=_bod_)a[a[0]+1]=a[a[0]]/_bod_,a[a[0]++]%=_bod_;
         return *this;
    }
    BN operator *(BN b) const{
        BN ans=BN();
        if(!a[0])return ans;
        if(!b[0])return ans;
        ans[0]=a[0]+b[0]-1;
        for(int i=1;i<=a[0];i++)
            for(int o=1;o<=b[0];o++)
                ans[i+o-1]+=a[i]*b[o];
        for(int i=1;i<=ans[0];i++)
            if(ans[i]>=_bod_)
                ans[i+1]+=ans[i]/_bod_,ans[i]%=_bod_;
        if(ans[ans[0]+1])ans[0]++;
        return ans;
    }
    void pri(){printf("%d",a[a[0]]);for(int i=a[0]-1;i>=1;i--)printf("%.4d",a[i]);}
}a,b,ans;
int main()
{
    freopen("3151.in","r",stdin);
    freopen("3151.out","w",stdout);
    int n=gi(),k=gi();
    if(n&1)a=n,b=(n+1)>>1;else a=n+1,b=n>>1;
    ans=k;(ans*(a*b)).pri();
    return 0;
}
原文地址:https://www.cnblogs.com/YJinpeng/p/5967867.html