NJUST 1929 water1

题目链接

#Algorithm
高精度
#Code

import java.math.BigInteger;
import java.util.Scanner;
class V
{
  int h, w;
}

public class Main 
{
  public static void main(String[] args)
  {
    Scanner cin = new Scanner(System.in);
    while (cin.hasNext())
    {
      int n = cin.nextInt();
      V[] a = new V[n];
      int maxh = 0;
      for (int i = 0; i < n; i++)
      {
        a[i] = new V();
        a[i].h = cin.nextInt();
        a[i].w = cin.nextInt();
        if (a[i].h > maxh) maxh = a[i].h;
      }
      maxh++;
      BigInteger ans;
      if (n == 0) ans = BigInteger.ONE; else ans = BigInteger.ZERO;
      for (int i = 0; i < n; i++)
        ans = ans.add(BigInteger.valueOf((maxh - a[i].h) * a[i].w));
      System.out.println(ans.toString());
    }
  }
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int maxn = 1e5 + 9;
int n;
struct BigInt
{
  static const int BASE = 1e8;
  static const int WIDTH = 8;
  vector<int> s;
  BigInt(long long num = 0) {*this = num;}
  BigInt operator = (long long num)
  {
    s.clear();
    do
    {
      s.push_back(num % BASE);
      num /= BASE;
    }while (num > 0);
    return *this;
  }
  BigInt operator + (const BigInt &b) const
  {
    BigInt c;
    c.s.clear();
    for (int i = 0, g =0; ; i++)
    {
      if (g == 0 && i >= s.size() && i >= b.s.size()) break;
      int x = g;
      if (i < s.size()) x+= s[i];
      if (i < b.s.size()) x+= b.s[i];
      c.s.push_back(x % BASE);
      g = x / BASE;
    }
    return c;
  }
};
struct V
{
  int h, w;
};
V a[maxn];
void solve()
{
  memset(a, 0, sizeof(a));
  int maxh = 0;
  for (int i = 0; i < n; i++)
  {
    scanf("%d%d", &a[i].h, &a[i].w);
    if (a[i].h > maxh) maxh = a[i].h;
  }
  BigInt ans;
  if (n == 0) ans = 1; else ans = 0;
  maxh++;
  for (int i = 0; i < n; i++)
  {
    ans = ans + BigInt((maxh - a[i].h) * a[i].w);
  }
  for (int i = ans.s.size() - 1; i >= 0; i--)
    cout << ans.s[i];
  cout << endl;
}
int main()
{
  while (scanf("%d", &n) != EOF)
  {
    solve();
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值