标签:高精度
题目大意:
分析:
AC code:
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#define pb push_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof a)
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
typedef long long LL;
typedef double DB;
typedef long double LD;
using namespace std;
void open_init()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
}
void close_file()
{
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
}
const int MAX = 2009;
const int M = 10;
struct Bignum
{
int a[MAX];
Bignum()
{
clr(a, 0);
a[0] = 1;
}
Bignum(int k)
{
clr(a, 0);
a[0] = 1;
if(k)
{
a[0] = 0;
while(k)
{
a[++a[0]] = k%M;
k /= M;
}
}
}
Bignum& operator = (const Bignum &b)
{
clr(a, 0);
memcpy(a, b.a, (b.a[0]+1)*sizeof(int));
return *this;
}
inline void read()
{
char str[MAX] = "\0";
scanf("%s", str);
a[0] = strlen(str);
per(i, a[0], 1)
a[a[0]-i+1] = str[i-1]-‘0‘;
}
inline void adjust()
{
rep(i, 1, a[0])
{
while(a[i] < 0) a[i+1]--, a[i] += M;
while(a[i] >= M) a[i+1]++, a[i] -= M;
}
while(a[a[0]+1]) a[0]++;
while(a[0] > 1 && !a[a[0]]) a[0]--;
}
inline void write()
{
per(i, a[0], 1)
putchar(a[i]+‘0‘);
}
}q, c, n, empty, ans;
inline bool operator < (const Bignum &a, const Bignum &b)
{
if(a.a[0] != b.a[0]) return a.a[0] < b.a[0];
per(i, a.a[0], 1)
if(a.a[i] != b.a[i])
return a.a[i] < b.a[i];
return false;
}
inline bool operator == (const Bignum &a, const Bignum &b)
{
if(a.a[0] != b.a[0]) return false;
rep(i, 1, a.a[0])
if(a.a[i] != b.a[i])
return false;
return true;
}
inline bool operator > (const Bignum &a, const Bignum &b)
{
if(a.a[0] != b.a[0]) return a.a[0] > b.a[0];
per(i, a.a[0], 1)
if(a.a[i] != b.a[i])
return a.a[i] > b.a[i];
return false;
}
inline bool operator <= (const Bignum &a, const Bignum &b)
{
return !(a > b);
}
inline bool operator >= (const Bignum &a, const Bignum &b)
{
return !(a < b);
}
inline Bignum operator + (const Bignum &a, const Bignum &b)
{
Bignum ret;
int len = max(a.a[0], b.a[0]);
rep(i, 1, len)
ret.a[i] = a.a[i]+b.a[i];
ret.a[0] = len;
ret.adjust();
return ret;
}
inline void operator += (Bignum &a, const Bignum &b)
{
a = a+b;
}
inline Bignum operator - (const Bignum &a, const Bignum &b)
{
Bignum ret;
int len = a.a[0];
rep(i, 1, len)
ret.a[i] = a.a[i]-b.a[i];
ret.a[0] = len;
ret.adjust();
return ret;
}
inline void operator -= (Bignum &a, const Bignum &b)
{
a = a-b;
}
inline Bignum operator * (const Bignum &a, int k)
{
Bignum ret;
ret.a[0] = a.a[0];
rep(i, 1, a.a[0])
ret.a[i] = a.a[i]*k;
ret.adjust();
return ret;
}
inline Bignum operator * (const Bignum &a, const Bignum &b)
{
Bignum ret;
per(i, a.a[0], 1)
ret = ret*M+b*a.a[i];
return ret;
}
template<class T>
inline Bignum operator *= (Bignum &a, const T &b)
{
a = a*b;
}
inline Bignum operator / (const Bignum &a, const Bignum &b)
{
Bignum ret, tmp;
ret.a[0] = a.a[0];
per(i, a.a[0], 1)
{
tmp = tmp*M+a.a[i];
int l = 0, r = 9;
while(l < r)
{
int mid = (l+r+1)>>1;
if(b*mid > tmp) r = mid-1;
else l = mid;
}
tmp -= b*l;
ret.a[i] = l;
}
ret.adjust();
return ret;
}
inline Bignum operator % (const Bignum &a, const Bignum &b)
{
return a-a/b*b;
}
int main()
{
open_init();
q.read(), c.read(), n.read();
if(q < n || c < n)
{
if(q < c) empty = c%n*q;
else empty = q%n*c;
}
else
{
Bignum t1 = q%n, t2 = c%n;
empty = min(t1*t2, (n-t1)*(n-t2));
}
ans = (q*c-empty)/n;
ans.write();
close_file();
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
sgu292:Field for the Cemetery(结论+高精度)
标签:高精度
原文地址:http://blog.csdn.net/qq_20118433/article/details/46984093