复(学)习化学时突然的一个 idea
期中考试成功探底。。。但是某些化学问题还是很有信息学价值的。。。
n 烷同分异构体计数。
这个题 fanhq666 出过,就是一个 dp。
设 f[i] 表示含有 i 个节点的无标号不同构的度数限制为 4 的有根树的个数。那么转移时枚举最多 3 个子树的大小,如果大小相同时用组合数,否则乘法原理就好了。
最后统计答案时找到中心为根,然后最多 4 个子树,每个大小不超过 [n / 2] - 1(除法取上整),同样的累计方法(组合数/乘法原理)统计一下就好了;双重心时需要把两个重心同时提上去统计一遍和刚才的答案累加。
没事闲的写了个比较全的高精度,先贴高精度模板。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} struct LL {
int len, A[510]; LL() { len = -1; }
LL(int x) {
A[1] = x; len = 1;
if(x) while(A[len] > 9) A[len+1] = A[len] / 10, A[len] %= 10, len++;
else len = -1;
} LL operator = (const int& t) {
A[1] = t; len = 1;
if(t) while(A[len] > 9) A[len+1] = A[len] / 10, A[len] %= 10, len++;
else len = -1;
return *this;
} LL operator + (const LL& t) const {
LL ans; ans.len = max(len, t.len);
for(int i = 1; i <= ans.len; i++) ans.A[i] = (i <= len ? A[i] : 0) + (i <= t.len ? t.A[i] : 0);
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator += (const LL& t) {
*this = *this + t;
return *this;
}
LL operator + (const int& t) const {
LL ans; ans.len = max(len, 1);
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i]; ans.A[1] += t;
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator += (const int& t) {
*this = *this + t;
return *this;
}
LL operator ++ () { // ++this;
*this = *this + 1;
return *this;
}
LL operator ++ (int x) { // this++;
*this = *this + 1;
return *this - 1;
} LL operator - (const LL& t) const {
LL ans; ans.len = max(len, t.len);
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i] - t.A[i];
for(int i = 1; i < ans.len; i++) if(ans.A[i] < 0) {
int tmp = (-ans.A[i] + 9) / 10;
ans.A[i+1] -= tmp; ans.A[i] += tmp * 10;
}
while(!ans.A[ans.len]) ans.len--;
return ans;
}
LL operator -= (const LL& t) {
*this = *this - t;
return *this;
}
LL operator - (const int& t) const {
LL ans; ans.len = len;
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i]; ans.A[1] -= t;
for(int i = 1; i < ans.len; i++) if(ans.A[i] < 0) {
int tmp = (-ans.A[i] + 9) / 10;
ans.A[i+1] -= tmp; ans.A[i] += tmp * 10;
}
while(!ans.A[ans.len]) ans.len--;
return ans;
}
LL operator -= (const int& t) {
*this = *this - t;
return *this;
}
LL operator -- () { // --this;
*this = *this - 1;
return *this;
}
LL operator -- (int x) { // this--;
*this = *this - 1;
return *this + 1;
} LL operator * (const LL& t) const {
LL ans; ans.len = len + t.len - 1;
if(len < 0 || t.len < 0) return ans.len = -1, ans;
for(int i = 1; i <= ans.len; i++) ans.A[i] = 0;
for(int i = 1; i <= len; i++)
for(int j = 1; j <= t.len; j++) ans.A[i+j-1] += A[i] * t.A[j];
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator *= (const LL& t) {
*this = *this * t;
return *this;
}
LL operator * (const int& t) const {
LL ans = t;
return ans * (*this);
}
LL operator *= (const int& t) {
*this = *this * t;
return *this;
} bool operator < (const LL& t) const {
if(len != t.len) return len < t.len;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return A[i] < t.A[i];
return 0;
}
bool operator > (const LL& t) const {
if(len != t.len) return len > t.len;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return A[i] > t.A[i];
return 0;
}
bool operator == (const LL& t) const {
if(len != t.len) return 0;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return 0;
return 1;
}
bool operator != (const LL& t) const {
return !((*this) == t);
}
bool operator <= (const LL& t) const {
return *this < t || *this == t;
}
bool operator >= (const LL& t) const {
return *this > t || *this == t;
} LL operator / (const LL& t) const {
LL ans, f = 0; ans.len = -1;
for(int i = 1; i <= len; i++) ans.A[i] = 0;
for(int i = len; i > 0; i--) {
f = f * 10 + A[i];
while(f >= t) {
f -= t; ans.A[i]++;
ans.len = max(ans.len, i);
}
}
return ans;
}
LL operator /= (const LL& t) {
*this = *this / t;
return *this;
}
LL operator / (const int& t) const {
LL ans; int f = 0; ans.len = -1;
for(int i = 1; i <= len; i++) ans.A[i] = 0;
for(int i = len; i > 0; i--) {
f = f * 10 + A[i];
while(f >= t) {
f -= t; ans.A[i]++;
ans.len = max(ans.len, i);
}
}
return ans;
}
LL operator /= (const int& t) {
*this = *this / t;
return *this;
} void print() {
if(len < 0){ putchar('0'); return ; }
for(int i = len; i > 0; i--) putchar(A[i] + '0'); putchar('\n');
return ;
}
} A, B; int main() {
while(1) {
A = read(); B = read();
(A + B).print();
(A - B).print();
(A * B).print();
(A / B).print();
(A++).print();
(++A).print();
(B--).print();
(--B).print();
} return 0;
}
/*
8997622 2333
*/
再贴这道题的程序。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
using namespace std; int read() {
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 1010 struct LL {
int len, A[510]; LL() { len = -1; }
LL(int x) {
A[1] = x; len = 1;
if(x) while(A[len] > 9) A[len+1] = A[len] / 10, A[len] %= 10, len++;
else len = -1;
} LL operator = (const int& t) {
A[1] = t; len = 1;
if(t) while(A[len] > 9) A[len+1] = A[len] / 10, A[len] %= 10, len++;
else len = -1;
return *this;
} LL operator + (const LL& t) const {
LL ans; ans.len = max(len, t.len);
for(int i = 1; i <= ans.len; i++) ans.A[i] = (i <= len ? A[i] : 0) + (i <= t.len ? t.A[i] : 0);
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator += (const LL& t) {
*this = *this + t;
return *this;
}
LL operator + (const int& t) const {
LL ans; ans.len = max(len, 1);
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i]; ans.A[1] += t;
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator += (const int& t) {
*this = *this + t;
return *this;
}
LL operator ++ () { // ++this;
*this = *this + 1;
return *this;
}
LL operator ++ (int x) { // this++;
*this = *this + 1;
return *this - 1;
} LL operator - (const LL& t) const {
LL ans; ans.len = max(len, t.len);
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i] - t.A[i];
for(int i = 1; i < ans.len; i++) if(ans.A[i] < 0) {
int tmp = (-ans.A[i] + 9) / 10;
ans.A[i+1] -= tmp; ans.A[i] += tmp * 10;
}
while(!ans.A[ans.len]) ans.len--;
return ans;
}
LL operator -= (const LL& t) {
*this = *this - t;
return *this;
}
LL operator - (const int& t) const {
LL ans; ans.len = len;
for(int i = 1; i <= ans.len; i++) ans.A[i] = A[i]; ans.A[1] -= t;
for(int i = 1; i < ans.len; i++) if(ans.A[i] < 0) {
int tmp = (-ans.A[i] + 9) / 10;
ans.A[i+1] -= tmp; ans.A[i] += tmp * 10;
}
while(!ans.A[ans.len]) ans.len--;
return ans;
}
LL operator -= (const int& t) {
*this = *this - t;
return *this;
}
LL operator -- () { // --this;
*this = *this - 1;
return *this;
}
LL operator -- (int x) { // this--;
*this = *this - 1;
return *this + 1;
} LL operator * (const LL& t) const {
LL ans; ans.len = len + t.len - 1;
if(len < 0 || t.len < 0) return ans.len = -1, ans;
for(int i = 1; i <= ans.len; i++) ans.A[i] = 0;
for(int i = 1; i <= len; i++)
for(int j = 1; j <= t.len; j++) ans.A[i+j-1] += A[i] * t.A[j];
for(int i = 1; i < ans.len; i++) if(ans.A[i] > 9) ans.A[i+1] += ans.A[i] / 10, ans.A[i] %= 10;
while(ans.A[ans.len] > 9) ans.A[ans.len+1] = ans.A[ans.len] / 10, ans.A[ans.len] %= 10, ans.len++;
return ans;
}
LL operator *= (const LL& t) {
*this = *this * t;
return *this;
}
LL operator * (const int& t) const {
LL ans = t;
return ans * (*this);
}
LL operator *= (const int& t) {
*this = *this * t;
return *this;
} bool operator < (const LL& t) const {
if(len != t.len) return len < t.len;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return A[i] < t.A[i];
return 0;
}
bool operator > (const LL& t) const {
if(len != t.len) return len > t.len;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return A[i] > t.A[i];
return 0;
}
bool operator == (const LL& t) const {
if(len != t.len) return 0;
for(int i = len; i > 0; i--) if(A[i] != t.A[i]) return 0;
return 1;
}
bool operator != (const LL& t) const {
return !((*this) == t);
}
bool operator <= (const LL& t) const {
return *this < t || *this == t;
}
bool operator >= (const LL& t) const {
return *this > t || *this == t;
} LL operator / (const LL& t) const {
LL ans, f = 0; ans.len = -1;
for(int i = 1; i <= len; i++) ans.A[i] = 0;
for(int i = len; i > 0; i--) {
f = f * 10 + A[i];
while(f >= t) {
f -= t; ans.A[i]++;
ans.len = max(ans.len, i);
}
}
return ans;
}
LL operator /= (const LL& t) {
*this = *this / t;
return *this;
}
LL operator / (const int& t) const {
LL ans; int f = 0; ans.len = -1;
for(int i = 1; i <= len; i++) ans.A[i] = 0;
for(int i = len; i > 0; i--) {
f = f * 10 + A[i];
while(f >= t) {
f -= t; ans.A[i]++;
ans.len = max(ans.len, i);
}
}
return ans;
}
LL operator /= (const int& t) {
*this = *this / t;
return *this;
} void print() {
if(len < 0){ putchar('0'); return ; }
for(int i = len; i > 0; i--) putchar(A[i] + '0');
return ;
}
}; LL f[maxn];
LL C(LL n, int m) {
LL sum = 1;
for(LL i = n; i >= n - m + 1; i--) sum *= i;
for(int i = 1; i <= m; i++) sum /= i;
return sum;
}
LL dp(int n) {
LL& ans = f[n];
if(ans > 0) return ans;
if(!n) return ans = 1;
// printf("dp(%d)\n", n);
for(int s1 = n - 1; s1 >= 0; s1--)
for(int s2 = s1; s2 >= 0; s2--) {
int s3 = n - s1 - s2 - 1;
if(s3 < 0) continue;
if(s2 < s3) break;
// printf("%d %d %d\n", s1, s2, s3);
if(s1 == s3) ans += C(dp(s1) + 2, 3);
else if(s1 == s2)
ans += C(dp(s1) + 1, 2) * dp(s3);
else if(s2 == s3)
ans += C(dp(s2) + 1, 2) * dp(s1);
else ans += dp(s1) * dp(s2) * dp(s3);
// printf("dp(%d): %lld\n", n, ans);
}
// printf("%d: %d\n", n, ans);
return ans;
} string Names[15] = {"¼×", "ÒÒ", "±û", "¶¡", "Îì", "¼º", "¸ý", "ÐÁ", "ÈÉ", "¹ï"};
string getname(int n) {
if(n <= 10) return Names[n-1] + string("Íé");
char Name[maxn]; memset(Name, 0, sizeof(Name));
sprintf(Name, "%dÍé", n);
return string(Name);
} int main() {
while(1) {
int n = read();
LL ans = 0, getrid = 0;
if(n & 1) {
for(int s1 = (n >> 1); s1 >= 0; s1--)
for(int s2 = s1; s2 >= 0; s2--)
for(int s3 = s2; s3 >= 0; s3--) {
int s4 = n - s1 - s2 - s3 - 1;
if(s4 < 0) continue;
if(s3 < s4) break;
// printf("%d %d %d %d\n", s1, s2, s3, s4);
if(s1 == s4) ans += C(dp(s1) + 3, 4);
else if(s1 == s3) ans += C(dp(s1) + 2, 3) * dp(s4);
else if(s2 == s4) ans += C(dp(s2) + 2, 3) * dp(s1);
else {
int S[4] = {s1, s2, s3, s4}, l = 0, r = 0;
LL tmp = 1;
while(r < 4) {
while(r < 3 && S[l] == S[r+1]) r++;
tmp *= C(dp(S[l]) + r - l, r - l + 1);
l = r = r + 1;
}
ans += tmp;
}
}
}
else {
for(int s1 = (n >> 1) - 1; s1 >= 0; s1--)
for(int s2 = s1; s2 >= 0; s2--)
for(int s3 = s2; s3 >= 0; s3--) {
int s4 = n - s1 - s2 - s3 - 1;
if(s4 < 0) continue;
if(s3 < s4) break;
// printf("%d %d %d %d\n", s1, s2, s3, s4);
if(s1 == s4) ans += C(dp(s1) + 3, 4);
else if(s1 == s3) ans += C(dp(s1) + 2, 3) * dp(s4);
else if(s2 == s4) ans += C(dp(s2) + 2, 3) * dp(s1);
else {
int S[4] = {s1, s2, s3, s4}, l = 0, r = 0;
LL tmp = 1;
while(r < 4) {
while(r < 3 && S[l] == S[r+1]) r++;
tmp *= C(dp(S[l]) + r - l, r - l + 1);
l = r = r + 1;
}
ans += tmp;
}
}
ans += C(dp(n >> 1) + 1, 2);
}
cout << getname(n); printf("ÓÐ "); ans.print(); puts(" ÖÖͬ·ÖÒì¹¹Ìå");
} return 0;
}
复(学)习化学时突然的一个 idea的更多相关文章
- PHP进行数据库操作时遇到的一个问题
PHP进行数据库操作时遇到的一个问题 昨天在进行数据库操作时,遇到了一个问题(用的是 wampserver 环境): <?php $link = @mysqli_connect('localho ...
- Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们。
Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 这个是我将鸟哥书上的进行了一下整理的,希望不要涉及到版权问题. 1.显示日期的 ...
- 当我学完Python时我学了些什么
本文是本人学完Python后的一遍回顾,加深理解而已,Python大神请过~ 学习Python的这几天来,觉得Python还是比较简单,容易上手的,就基本语法而言,但是有些高级特性掌握起来还是有些难度 ...
- ios 仿新浪微博 UINavigationController 向左滑动时显示上一个控制器的View.
仿新浪微博 UINavigationController 向左滑动时显示上一个控制器的View. 实现原理,UINavigationController 的 self.view显示时把当前显示的vie ...
- L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误(转)
L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误 错误描述:“ L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇到了一个处理错误” 只有这个没有错误码. ...
- 启动多个eclipse 时,因为一个另一个启动报错,
启动多个eclipse 时,因为一个另一个启动报错, 原因: 可能是 有一个 eclipse 中 的 tomcat 配置出错:preference中 tomcat 配置 context dec ...
- json 数据类型,后台在组数据时,错一个标点符号,前端都解析不出来。
json 数据类型,后台在组数据时,错一个标点符号,前端都解析不出来.
- 在Hive中执行DDL之类的SQL语句时遇到的一个问题
在Hive中执行DDL之类的SQL语句时遇到的一个问题 作者:天齐 遇到的问题如下: hive> create table ehr_base(id string); FAILED: Execut ...
- 安装dede UTF_8时报出了一个致命错误和警告,最后不能显示网站后台和首页了
安装dede UTF_8时报出了一个致命错误和警告,最后不能显示网站后台和首页了.报错如下: 登陆首页显示:Fatal error: Call to undefined function ParCv( ...
随机推荐
- RHEL 6.5----iscsi多路径存储
主机名 IP master eth0: 192.168.30.130(NAT) eth1: 192.168.17.130(VMNet4) node-1 eth0: 192.168.30.131(NAT ...
- solr facet查询及solrj 读取facet数据[转]
solr facet查询及solrj 读取facet数据 | 所属分类:solr facet solrj 一. Facet 简介 Facet 是 solr 的高级搜索功能之一 , 可以给用户提供更 ...
- php 使用serialize() 和 unserialize() 让对象成超级变量
手册里面的原话和一些总结: php函数serialize()与unserialize()说明及案例.想要将已序列化的字符串变回 PHP 的值,可使用unserialize().serialize()可 ...
- poj3252Round Numbers
链接 也算是组合 以前按组合做过一次 忘记怎么做的了 这次按dp写的 dp[i][j][g][k] 表示第i位为k(0|1)而且有j个1,g个0的情况数 貌似写的麻烦了...这一类的题,进行逐位计算就 ...
- 从零开始docker部署flask
1.下载一个Ubuntu镜像 2.启动镜像,使用apt-get安装python.安装pip,建议也装个vim吧 3.通过以上的容器生成一个新的镜像,命令如下docker commit afcaf46e ...
- (3)《Head First HTML与CSS》学习笔记---CSS入门
1.O‘Reilly的<CSS PocketReference>是一本不错的CSS参考小书,记录了常用的元素属性. 2.元素选择器的作用强于继承的作用:用户定义强于浏览器默认(以下所有讨论 ...
- iOS 根据屏幕宽度, 高度判断手机设备
#define iPhone_5 [UIScreen mainScreen].bounds.size.width == 320.0 #define iPhone_6 [UIScreen mainScr ...
- RxJava的map方法与flatMap方法
简单讲,map和flatMap都是来完成Observable构造的数据到Observer接收数据的一个转换,这么说有点绕
- ABAP和XML数据格式互相转换的两种方式
ABAP和XML数据格式互相转换是广大开发人员经常遇到的需求.本文介绍两种方式. 1. ABAP提供了一个工具类cl_proxy_xml_transform,通过它的两个方法abap_to_xml_x ...
- android 解密工具
androguard. 这个是python写的 安装: pip install androguard