复(学)习化学时突然的一个 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( ...
随机推荐
- 单机版solr6.3和分布式solr6.3的安装部署
一.单机版的solr部署 我的是在windows下安装的,linux同理 1. 安装JDK8,并配置好环境变量,一般我们经常开发的电脑上应该都有JDk了,所以这一步可以忽略. 2. 解压solr6.3 ...
- Ionic之ui-sref引入图片,图片部分挡住解决方案
ionic图片设置大小跟图片像素相同,但是使用ui-sref="parkInfo"上半部分图片会挡住,增加height的高度,就可以显示原本图片 页面: <ion-conte ...
- vue在使用ajax获取数据时,两种方法(jquery和vue_resource)
@{ Layout = null;} <!DOCTYPE html> <html><head> <meta name="viewport ...
- VUE学习——vue的内部指令学习(趁自己没忘,学习记录一下)
1.v-if&v-else&v-show v-if用来判断是否加载html的DOM,v-if和v-else一般是一起用的. v-show相当于display,DOM已经加载出来了,这个 ...
- 解决Ueditor在bootstarp 模态框中全屏问题
基本的一些配置就不说了.先说一下要注意的问题:首先是zIndex的设置.记住最好都显示设置模态框和ueditor的zIndex.理清他们的层叠关系. 特别是用到ueditor里面的图片上传功能的更要设 ...
- 【HEVC帧间预测论文】P1.6 A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence
A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence <HEVC标准介绍.HEVC帧间预测论文笔记&g ...
- innerHTML的性能问题
看到一遍文章When innerHTML isn’t Fast Enough,反应了innerHTML在操作量大了以后的性能下降的问题. 并且给出了一个replaceHTML的函数 function ...
- Database coalesce
coalesce 语法 注意:连接操作符“||”是一个值得注意的例外. 例如,空值加任何值都是空值,空值 乘任何值也都是空值,依此类推. 参数 expression 任何类型的表达式. n 表示可以指 ...
- 洛谷 P2680 运输计划
题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航道连通了 L 国的所有星球. 小 P 掌管一家 ...
- 51nod 1432 独木舟
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承 ...