二次联通门 : 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. Xgboost GPU配置

    眼残cmake版本配错了搞了半天,简单记录一下,老规矩,参考一下官方的文档. git clone --recursive https://github.com/dmlc/xgboost cd xgbo ...

  2. 指针 vs 引用 (2)

    这波要针对上篇分析里 标红的问题(成员变量用 T,T&啥情况)继续思考, 要学习以下材料: 1. 知乎上:用指针还是引用 2. StackOverflow上的相关问题 https://stac ...

  3. drf--权限组件

    目录 权限简介 局部使用 全局使用 源码分析 权限简介 权限就是某些功能只对特定的用户开放,比如django中创建用户可分为超级用户和普通用户,此时超级用户就有权限进入后台管理系统,而普通用户就没有权 ...

  4. JavaScript---正则使用,日期Date的使用,Math的使用,JS面向对象(工厂模式,元模型创建对象,Object添加方法)

    JavaScript---正则使用,日期Date的使用,Math的使用,JS面向对象(工厂模式,元模型创建对象,Object添加方法) 一丶正则的用法 创建正则对象: 方式一: var reg=new ...

  5. MTSC2019-深圳站 议题征集

    议题截止时间 11月初 议题投递地址 topic@testerhome.com   臣一路走来,没有敌人,看见的都是朋友和师长 —司马懿 关于中国移动互联网测试大会 MTSC 大会(中国移动互联网测试 ...

  6. 安装vivado 2016.1时出错

    在将vivado 2016.1安装到d:\ xilinx时,发生以下错误: 提取存档D时遇到 错误:\ Xilinx_Vivado_SDK_2016.1_0409_1 \ payload \ rdi_ ...

  7. 【转载】 C#中ArrayList使用GetRange方法获取某一段集合数据

    在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,可以使用GetRange方法来获取集合中指定索引位置开始的一整段集合数据组成一个新的集合,GetRange方法的签名为virtual ...

  8. MAC PHP7 如何disable xdebug

    1. 查看xdebug当前状态是否是enable 打开terminal,输入: php -m | grep xdebug terminal返回xdebug,说明现在xdebug是enable状态. 2 ...

  9. Linux命令passwd

    passwd 简单说明:passwd命令的用法也很多,我们只选如下的几个参数加以说明:想了解更多,请参考man passwd或passwd --help :passwd [OPTION...] pas ...

  10. ZYNQ7000性能分析

    提到自动驾驶,机器人视觉,高清摄像机,都要想到摄像头这个单元,先前本侠也讲过一些FPGA应用在高清摄像头和机器视觉中的深度摄像头以及双目摄像头等,FPGA在里面的作用主要是对采集的图像进行处理,对图像 ...