[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 ...
随机推荐
- js原生实现div渐入渐出
jq对渐入渐出进行封装,简单的使用连个方法就可以实现.fadeIn(),fadeOut();如果我们界面没有使用jq那么原生怎么实现呢? 我们讲解一下,这个原理.当我们要实现渐入的时候,首先是让隐藏的 ...
- STL中vector、set、list和map
- 将表单数据转换为json代码分享
<body> <form action="#" method="post" id="form1"> <inpu ...
- day 7-14 数据库完整性约束
一. 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性 主要分为: PRIMARY KEY 标示该字段为表的主键,可以唯一的标示记录 FOREIGN KEY 标示该 ...
- C# Note22: 《Effective C#》笔记
参考:<Effective C#>快速笔记(一)- C# 语言习惯 参考:<Effective C#>快速笔记(二)- .NET 资源托管 参考:<Effective C ...
- Junit概述
Junit -> java unit.也就是说Junit是xunit家族中的一员. unit <- unit test case,即单元测试用例. Junit = java uni ...
- Python __slots__ 作用
参考:https://blog.csdn.net/u010733398/article/details/52803643 https://blog.csdn.net/sxingming/artic ...
- python之路--动态传参,作用域,函数嵌套
一 . 动态传参(重点) * , ** * 与 ** * 在形参位置. * 表示不定参数, 接收的是位置参数 接收到的位置参数的动态传参: 都是元组 def eat(*food): # 在形参这里 ...
- mvn clean compile package install deploy
(1) package 目的是打包,在pom中,如果是jar就会打包成jar,如果是war就会打包成war 在pom.xml中: <modelVersion></modelVersi ...
- JS--innerHTML属性
innerHTML属性,不是DOM的组成部分(常用) 获取标签里的文本内容,var span=document.getElementById("span").innerHTML; ...