codevs 2803 爱丽丝·玛格特罗依德
二次联通门 : 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 爱丽丝·玛格特罗依德的更多相关文章
- Codevs 1021 (玛丽卡)
题目描述 Description 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他们不住在同一个城市,因此她开始准备她的长途旅行. 在这个国家中每两个城市之间最多只有一条路相通,并且我们 ...
- OJ 21651::Cow Hurdles(佛罗一德的变式)
Description Farmer John wants the cows to prepare for the county jumping competition, so Bessie and ...
- 通用js地址选择器
用js实现通用的地址选择器,省份,城市,地区自动关联更新 点击下面查看详细代码: http://runjs.cn/code/s8sqkhcv 关键地址库代码: var addr_arr = new A ...
- OC省字典的数组摘要集
开放式党员 NSString *filePath = @"/Users/dlios/Downloads/area.txt"; 推断错误值 打印出来 NSError *error = ...
- MVC图片上传详解 IIS (安装SSL证书后) 实现 HTTP 自动跳转到 HTTPS C#中Enum用法小结 表达式目录树 “村长”教你测试用例 引用provinces.js的三级联动
MVC图片上传详解 MVC图片上传--控制器方法 新建一个控制器命名为File,定义一个Img方法 [HttpPost]public ActionResult Img(HttpPostedFile ...
- react 写的省市三级联动
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>Ba ...
- 天气预报API(一):全国城市代码列表(“旧编码”)
说明 2016-12-09 补充 (后来)偶然发现中国天气网已经有城市ID列表的网页... 还发现城市编码有两种,暂且称中国天气网这些编码为旧标准 "旧编码"的特征是 9个字符长度 ...
- 全国行政区划代码(json对象版)
var area = {"110000":"北京市","110100":"北京市","110101" ...
- 省市区三级联动JS
HTML Part <select id="prov" onchange="getCity(this.value);" required="re ...
随机推荐
- C# Modbus 数据读取 使用NModBus4库
ModBus通讯协议 方法名 作用 所需参数 返回值 对应功能码 ReadCoils 读取DO的状态 从站地址(8位) byte slaveAddress 起始地址(16位) ushort start ...
- C# 练习题 利用条件运算符的嵌套来完成分数等级划分
题目:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示.1.程序分析:(a>b)?a:b这是条件运算符的基本例子. cla ...
- 详解JS与Jquery获得的对象的区别与联系
世上无难事只怕有心人,敲代码也一样只要你用心去搞懂一件事,即使一个小小的用法对你以后也会有很大的作用: 项目虽然赶得紧但是有些问题百度找完答案解决之后,也要自己梳理一遍做到心领神会!!!今天就直接来上 ...
- Jmeter的安装与配置。
1.本机配置好JAVA环境. 2.官网下载压缩包,在任意目录下解压. 3.修改配置文件 ,打开Jmeter的bin目录下jmeter.porperties,修改 language=zh_CN samp ...
- DOM创建节点
1.DOM--document object model 常用的节点类型: 元素节点:(标签) 属性节点:(标签里的属性) 文本节点:(文本节点) 2,document有个属性叫nodetype,返回 ...
- Kubemetes
将应用docker化,配合ETCD.kubernetes等工具在容器的层面上实现高可用和负载均衡 容器化部署 容器化部署应用具有灵活.高效的使用资源,容器可以包含其所需的全部文件,如同在虚拟机上部署应 ...
- vue 封装公用函数
Vue 函数封装 格式化浏览器时间 /** * 格式化时间 * @param params * @param blo 默认为true * @returns {string} * @constructo ...
- go frame框架,关闭启动时打印的路由列表已经debug信息
import ( "github.com/gogf/gf/frame/g" "github.com/gogf/gf/os/glog" ) func main() ...
- k8s 之service资源介绍(三)
kubernetes service资源 apiVersion: v1 kind: Service metadata: name: kubia spec: ports: - port: 80 targ ...
- python工程化最佳实践
1.pipenv 真实环境 vs virtualenv vs pipenv 2.自定义用户模型 继承BaseUserManager和AbstractBaseUser,在settings中指定AUTH_ ...