[HEOI2014]逻辑翻译(分治)
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int N=(<<)+;
double x;
int n,top,p[N];
char s[N];
inline int rd(){
int x=;char c=getchar();bool f=;
while(!isdigit(c)){if(c=='-')f=;c=getchar();}
while(isdigit(c)){x=(x<<)+(x<<)+(c^);c=getchar();}
return f?-x:x;
}
ll gcd(ll x,ll y){if(x<)x=-x;if(y<)y=-y;return y?gcd(y,x%y):x;}
struct fs{
ll x,y;
fs operator +(const fs &b)const{
ll xx=x*b.y+y*b.x,yy=y*b.y*;
ll g=gcd(yy,xx);
xx/=g;yy/=g;
return fs{xx,yy};
}
fs operator -(const fs &b)const{
ll xx=x*b.y-y*b.x,yy=y*b.y*;
ll g=gcd(yy,xx);
xx/=g;yy/=g;
return fs{xx,yy};
}
}dp[N];
void dfs(int num,int x){
if(num>n)return;
p[++top]=x|(<<num-);
dfs(num+,x|(<<num-));dfs(num+,x);
}
int main(){
n=rd();
for(int i=;i<(<<n);++i){
int o=;scanf("%s%lf",s+,&x);
for(int j=;j<=n;++j){
o<<=;o|=(s[j]=='+'?:);
}
if(x>)dp[o].x=(int)(x*+0.1);//因为要向0取整,所以要判断正负
else dp[o].x=(int)(x*-0.1);
dp[o].y=;
ll g=gcd(dp[o].x,dp[o].y);
dp[o].x/=g;dp[o].y/=g;
}
for(int i=(<<n-);i>=;i>>=)
for(int j=;j<(<<n);j+=(i<<))
for(int k=;k<i;++k){
fs x=dp[k+j],y=dp[k+i+j];
dp[k+j]=y-x;dp[k+i+j]=x+y;
}
for(int i=;i<(<<n);++i){
int x=i,l=,r=(<<n)-;
while(l!=r){
int mid=(l+r)>>;
if(x&)r=mid;else l=mid+;x>>=;
}
if(l<i)swap(dp[l],dp[i]);
}
dfs(,);
for(int i=;i<(<<n);++i){
int x=p[i];
if(!dp[x].x)continue;
if(dp[x].y<)dp[x].y=-dp[x].y,dp[x].x=-dp[x].x;
if(dp[x].y!=)
printf("%lld/%lld ",dp[x].x,dp[x].y);
else printf("%lld ",dp[x].x);
for(int j=;j<=n;++j)if(x&(<<j-))printf("x%d",j);
printf("\n");
}
return ;
}
[HEOI2014]逻辑翻译(分治)的更多相关文章
- [HEOI2014]逻辑翻译
ywy_c_asm的良心题解 是道好题 体现了二进制位的形象递归思想,以及将FWT的思路(都是拆位分治)用到题目中的典范 可以暴力高斯消元.完全没有利用2^N以及+-1的良好性质 发现项数,方程和二进 ...
- 洛谷 4106 / bzoj 3614 [HEOI2014]逻辑翻译——思路+类似FWT
题目:https://www.luogu.org/problemnew/show/P4106 https://www.lydsy.com/JudgeOnline/problem.php?id=3614 ...
- 【Moqui业务逻辑翻译系列】Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和机会
h1. Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和合作机会 h4. Ideas to incorporat ...
- 【Moqui业务逻辑翻译系列】Shipment Receiver Receives Shipment with Packing Slip but no PO
Shipment Receiver receives shipment. It has invoice tucked into it. Receiver records vendor name, ve ...
- 【Moqui业务逻辑翻译系列】Story of Online Retail Company 在线零售公司的故事
h1. Story of Online Retail Company 在线零售公司的故事 Someone decides to sell a product. [Product Marketer Ma ...
- 【Moqui业务逻辑翻译系列】--UBPL index
h2. [UBPL Introduction] ubpl介绍h2. [Actor Definitions] 行为定义h2. General Business Process Stories 通常的商业 ...
- 【Moqui业务逻辑翻译系列】--UBPL Introduction同意的商业处理文库介绍
h1. UBPL Introduction 通用的商业处理文库介绍h4. Why a Universal Business Process Library? 为什么需要通用的商业处理文库? The g ...
- 洛谷 P4106 / bzoj 3614 [ HEOI 2014 ] 逻辑翻译 —— 思路+递归
题目:https://www.luogu.org/problemnew/show/P4106 https://www.lydsy.com/JudgeOnline/problem.php?id=3614 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- IdentityServer4【Introduction】之包和项目构建
包和项目构建 IdentityServer包含了以下的nuget包: IdentityServer4 nuget | github 这个包包含了IdentityServer核心的组成部分,有对象模型, ...
- 快速理解Git结构
git pull:拉取远程服务器最新代码到本地(会自动merge) git add:将本地代码添加到暂存区 git commit:将暂存区的所有内容提交到当前分支(git会自动为我们创建第一个分支 ...
- [转帖]cmd批处理常用符号详解
cmd批处理常用符号详解 https://www.jb51.net/article/32866.htm 很多符号 还是不清楚的.. 批处理能够极大的提高 工作效率 需要加强深入学习. 1.@一般在 ...
- Mission Impossible 6
题目:Mission Impossible 6 题目链接:http://hihocoder.com/problemset/problem/1228 题目大意: 大概就是让我们写一个代码模拟文本编辑器的 ...
- Docker实现运行tomcat并部署项目war包,并实现挂载目录
之前写的有点乱,现在再来整理一下docker的简单部署运行 借鉴博客:https://blog.csdn.net/qq_32351227/article/details/78673591 一.dock ...
- Eclipse导入工程后出现中文乱码
Eclipse之所以会出现乱码问题是因为eclipse编辑器选择的编码规则是可变的.一般默认都是UTF-8或者GBK,当从外部导入的一个工程时,如果该工程的编码方式与eclipse中设置的编码方式不同 ...
- 谈谈B-树和B+树及其应用
待更!!! B-树和B+树的应用:数据搜索和数据库索引 B+/-Tree原理及mysql的索引分析 从B树.B+树.B*树谈到R 树 B树.B-树.B+树.B*树
- iframe全屏显示
<iframe webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=" ...
- Linux基础学习(16)--备份与恢复
第十六章——备份与恢复 一.备份概述 1.Linux系统需要备份的数据: 2.备份策略: 二.dump和restore命令 1.dump命令: 2.restore命令:
- c++ string去除首尾 空格、\n、\r、\t
string s = " test "; size_t n = s.find_last_not_of(" \r\n\t"); if (n != string:: ...