二次联通门 : codevs 2803 爱丽丝·玛格特罗依德

/*
codevs 2803 爱丽丝·玛格特罗伊德

   高精 + 找规律 显然, 能拆3就多拆3
不能拆就拆2 注意特判一下 */
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cassert>
#include <algorithm> #define int64 long long using namespace std; #define Max 105 const int B = ;
const int L = ; inline int intcmp(int a, int b)
{
if (a > b)
return ;
else if (a < b)
return -;
else
return ;
} void read (int &now)
{
now = ;
register char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
}
struct BigInt
{ vector<int> a;
BigInt(){}
BigInt(int n)
{
while (n > )
a.push_back(n % B), n /= B;
} BigInt(int64 n)
{
while (n > )
a.push_back(n % B), n /= B;
}
inline void clr0()
{
while (!a.empty() && a.back() == )
a.pop_back();
}
inline BigInt &operator+=(const BigInt &rhs)
{
a.resize(max(a.size(), rhs.a.size()));
int t = ;
for (int i = ; i < (int)rhs.a.size(); i++)
{
a[i] += rhs.a[i] + t;
t = a[i] >= B;
a[i] -= B & (-t);
}
for (int i = (int)rhs.a.size(); t != && i < (int)a.size(); i++)
{
a[i] += t;
t = a[i] >= B;
a[i] -= B & (-t);
}
if (t != )
a.push_back(t);
return *this;
}
inline BigInt &operator-=(const BigInt &rhs)
{
a.resize(max(a.size(), rhs.a.size()));
int t = ;
for (int i = ; i < (int)rhs.a.size(); i++)
{
a[i] -= rhs.a[i] + t;
t = a[i] < ;
a[i] += B & (-t);
}
for (int i = (int)rhs.a.size(); t != && i < (int)a.size(); i++)
{
a[i] -= t;
t = a[i] < ;
a[i] += B & (-t);
}
clr0();
return *this;
}
inline BigInt &operator*=(const BigInt &rhs)
{
int na = (int)a.size();
a.resize(na + rhs.a.size());
for (int i = na - ; i >= ; i--)
{
int ai = a[i];
int64 t = ;
a[i] = ;
for (int j = ; j < (int)rhs.a.size(); j++)
{
t += a[i + j] + (int64)ai * rhs.a[j];
a[i + j] = t % B;
t /= B;
}
for (int j = (int)rhs.a.size(); t != && i + j < (int)a.size(); j++)
{
t += a[i + j];
a[i + j] = t % B;
t /= B;
}
assert(t == );
}
clr0();
return *this;
}
inline BigInt &operator/=(const BigInt &rhs)
{
return *this = div(rhs);
}
inline BigInt &operator%=(const BigInt &rhs)
{
return div(rhs), *this;
}
inline BigInt &shlb(int l = )
{
if (a.empty())
return *this;
a.resize(a.size() + l);
for (int i = (int)a.size() - ; i >= l; i--)
a[i] = a[i - l];
for (int i = ; i < l; i++)
a[i] = ;
return *this;
}
inline BigInt &shrb(int l = )
{
for (int i = ; i < (int)a.size() - l; i++)
a[i] = a[i + l];
a.resize(max((int)a.size() - l, ));
return *this;
}
inline int cmp(const BigInt &rhs) const
{
if (a.size() != rhs.a.size())
return intcmp(a.size(), rhs.a.size());
for (int i = (int)a.size() - ; i >= ; i--)
if (a[i] != rhs.a[i])
return intcmp(a[i], rhs.a[i]);
return ;
}
inline BigInt div(const BigInt &rhs)
{
assert(!rhs.a.empty());
if (rhs > *this)
return ;
BigInt q, r;
q.a.resize((int)a.size() - (int)rhs.a.size() + );
for (int i = (int)a.size() - ; i > (int)a.size() - (int)rhs.a.size(); i--)
{
r.shlb();
r += a[i];
}
for (int i = (int)a.size() - (int)rhs.a.size(); i >= ; i--)
{
r.shlb();
r += a[i];
if (r.cmp(rhs) < )
q.a[i] = ;
else
{
int le = , ri = B;
while (le != ri)
{
int mi = (le + ri) / ;
if ((rhs * mi).cmp(r) <= )
le = mi + ;
else
ri = mi;
}
q.a[i] = le - ;
r -= rhs * q.a[i];
}
}
q.clr0();
*this = r;
return q;
}
friend inline BigInt operator+(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res += rhs;
}
friend inline BigInt operator-(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res -= rhs;
}
friend inline BigInt operator*(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res *= rhs;
}
friend inline BigInt operator/(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res.div(rhs);
}
friend inline BigInt operator%(const BigInt &lhs, const BigInt &rhs)
{
BigInt res = lhs;
return res.div(rhs), res;
}
friend inline ostream &operator<<(ostream &out, const BigInt &rhs)
{
if (rhs.a.size() == )
out << "";
else
{
out << rhs.a.back();
for (int i = (int)rhs.a.size() - ; i >= ; i--)
out << setfill('') << setw(L) << rhs.a[i];
}
return out;
}
friend inline bool operator<(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) < ;
}
friend inline bool operator<=(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) <= ;
}
friend inline bool operator>(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) > ;
}
friend inline bool operator>=(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) >= ;
}
friend inline bool operator==(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) == ;
}
friend inline bool operator!=(const BigInt &lhs, const BigInt &rhs)
{
return lhs.cmp(rhs) != ;
}
}; int N;
BigInt Answer = ; int main (int argc, char *argv[])
{ for (read (N); N; )
{
if (N == )
{
N -= ;
Answer *= ;
}
else if (N >= )
{
N -= ;
Answer *= ;
}
else if (N == )
{
N -= ;
Answer *= ;
}
else if (N == )
{
puts ("");
return ;
}
}
cout << Answer;
return ;
}

codevs 2803 爱丽丝·玛格特罗依德的更多相关文章

  1. Codevs 1021 (玛丽卡)

    题目描述 Description 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他们不住在同一个城市,因此她开始准备她的长途旅行. 在这个国家中每两个城市之间最多只有一条路相通,并且我们 ...

  2. OJ 21651::Cow Hurdles(佛罗一德的变式)

    Description Farmer John wants the cows to prepare for the county jumping competition, so Bessie and ...

  3. 通用js地址选择器

    用js实现通用的地址选择器,省份,城市,地区自动关联更新 点击下面查看详细代码: http://runjs.cn/code/s8sqkhcv 关键地址库代码: var addr_arr = new A ...

  4. OC省字典的数组摘要集

    开放式党员 NSString *filePath = @"/Users/dlios/Downloads/area.txt"; 推断错误值 打印出来 NSError *error = ...

  5. MVC图片上传详解 IIS (安装SSL证书后) 实现 HTTP 自动跳转到 HTTPS C#中Enum用法小结 表达式目录树 “村长”教你测试用例 引用provinces.js的三级联动

    MVC图片上传详解   MVC图片上传--控制器方法 新建一个控制器命名为File,定义一个Img方法 [HttpPost]public ActionResult Img(HttpPostedFile ...

  6. react 写的省市三级联动

    <!DOCTYPE html><html><head> <meta charset="utf-8"> <title>Ba ...

  7. 天气预报API(一):全国城市代码列表(“旧编码”)

    说明 2016-12-09 补充 (后来)偶然发现中国天气网已经有城市ID列表的网页... 还发现城市编码有两种,暂且称中国天气网这些编码为旧标准 "旧编码"的特征是 9个字符长度 ...

  8. 全国行政区划代码(json对象版)

    var area = {"110000":"北京市","110100":"北京市","110101" ...

  9. 省市区三级联动JS

    HTML Part <select id="prov" onchange="getCity(this.value);" required="re ...

随机推荐

  1. delphi 格式转换

    TO_CHAR 是把日期或数字转换为字符串 TO_DATE 是把字符串转换为数据库中得日期类型转换函数TO_NUMBER 将字符转化为数字 TO_CHAR 使用TO_CHAR函数处理数字 TO_CHA ...

  2. Oracle使用中的常规操作总结

    写一篇在使用Oracle过程中一些常用的操作,以便于忘记的时候查看 一.创建用户和给用户赋予权限 create user 用户名 identified by 密码; --12c一下版本 create ...

  3. wangeditor视频

    wangeditor网址http://www.wangeditor.com/ 目前使用的是3.11版本 使用步骤 1.引用wangEditor.min.js 2.代码 2.1 取得函数var E = ...

  4. Boleto 银行付款

    Boleto是由多家巴西银行共同支持的一种支付方式,在巴西占据绝对主导地位,客户可以到巴西任何一家银行.ATM机.caipiao网点或使用网上银行授权银行转账. 该支付渠道有如下特点:1. 一旦付款, ...

  5. asp.net 自定义特性

    今天看张子阳的.net中的反射(反射特性)一文,觉得反射配合自定义的特性确实还挺有用,之前看书.看博客之后好多心血来潮敲的代码随便往桌面上一放,时间一久,连自己也分不清它们是干嘛的了,然后就是删除,虽 ...

  6. vue组件6 使用vue添加样式

    class绑定,内联样式 数组语法 :class="[stylename]"    js:data{stylename:classname} 对象语法:class={stylena ...

  7. javascript:void(0)的含义

    void关键字介绍 首先,void关键字是javascript当中非常重要的关键字,该操作符指定要计算或运行一个表达式,但是不返回值. 语法格式: void func() void(func()) 实 ...

  8. 下拉菜单旋转出现css

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  9. git 从远程克隆代码并实现分支开发,合并分支,上传本地代码到远程

    首先确认你已经安装了git 1.克隆远程代码到本地的操作 git clone 地址   打开git操作命令行 鼠标右键点击        复制需要克隆的项目的地址类似下面的ssh     输入命令进行 ...

  10. JavaScript 之 基本包装类型

    基本包装类型 为了方便操作基本数据类型,JavaScript 还提供了三个特殊的引用类型:String/Number/Boolean.  下面先看一段代码: var s1 = "Hello ...