[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 ...
随机推荐
- 如何使用 Docker 来限制 CPU、内存和 IO等资源?
如何使用 Docker 来限制 CPU.内存和 IO等资源?http://www.sohu.com/a/165506573_609513
- Docker bridge br0 pipework
Docker Centos7 下建立 Docker 桥接网络 - weifengCorp - 博客园https://www.cnblogs.com/weifeng1463/p/7468497.html ...
- Oracle NVL空值处理函数
--NVL空值处理函数 --需求:显示价格表中业主类型ID为1的价格记录 如果上限值为null,则显示9999999 ) from dual; select * from t_pricetable ) ...
- flutter image_picker使用照相机
dependencies: image_picker: ^0.4.12+1 最新的^0.5+9编译无法通过 import 'dart:io'; import 'dart:async'; import ...
- 爬取B站视频
先安装you_get pip install you_get 爬取代码,爬了个ASMR的,学习困了自我催眠 import sys from you_get import common as you_g ...
- 爬虫 之Requests库的详细使用
1.什么是Requests? Requests是用Python语言编写的,基于urllib3来改写的,采用Apache2 Licensed 来源协议的HTTP库. 它比urllib更加方便,可以节约我 ...
- 运维常用mysql语句
1..select @@version; ##查询当前mysql的版本. 2. show variables like 'port';##查看mysql实例的端口. 3.show variables ...
- fiddler 笔记-设置断点
设置断点后,可以修改httprequest的任何信息包括:host,cookie或都表单中的数据 1 Fiddler--rules--Automatic Breakpoint --before Req ...
- Java 下载 HLS (m3u8) 视频
下载索引文件 public String getIndexFile() throws Exception{ URL url = new URL(originUrlpath); //下载资源 Buffe ...
- Atcoder Beginner Contest 118 D-Match Matching(完全背包)
题目链接 题意就是给N根火柴,M个数(M只能是1到9,对应的数字也只能是1到9),只能用这M个出现过的数(但每个数可以随便用多少个,只要火柴够)来拼出一个数字(拼出1,2,3,4,5,6,7,8,9分 ...