[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 ...
随机推荐
- MYSQL业务数据简单脱敏方案
removesensitiveinformationplan.sh #!/bin/sh #!在模拟库上运行如下脚本 #!生产库crm-db #!模拟库crm-mock #!.备份生产库 mysqldu ...
- PyCharm3.0默认快捷键
PyCharm3.0默认快捷键(翻译的) 1.编辑(Editing) Ctrl + Space 基本的代码完成(类.方法.属性) Ctrl + Alt + Space 快速导入任意类 Ctrl + S ...
- IdentityServer4【QuickStart】之切换到混合流并且添加API访问
切换到混合流并且添加API访问 前面的示例中我们开发了API访问和用户认证,现在我们要将两个合并到一起. OpenID Connect&OAuth 2.0组合的美妙之处是,你可以使用单一协议和 ...
- [转帖]Windows NT 之父 - David Cutler
Windows NT 之父 - David Cutler https://www.cnblogs.com/wangwust/p/6826200.html 曾经下过 夺路狂奔的电子书 但是还没看完.. ...
- Flutter 常用工具类库common_utils
地址:https://pub.flutter-io.cn/packages/common_utils#-readme-tab- Dart常用工具类库 common_utils 1.TimelineUt ...
- NIO服务器与客户端
这里客户端没有采用NIO形式 服务器: package com.util.Server.NIO; import javax.print.DocFlavor;import java.io.IOExcep ...
- js auto hover button & html5 button autofocus
js auto hover button & html5 button autofocus input // html 5 <input name="myinput" ...
- mysql从入门到精通
解决MySQL Got a packet bigger than 'max_allowed_packet' bytes 问题在一次性向mysql插入的数据过大,可在my.ini中修改max_allow ...
- QTP 自动化测试桌面程序--笔记(关闭 启动程序脚本) 、安装
0 安装qtp .exe 文件 安装 插件文件(如delph) 1 关闭 启动程序: 将要操作的程序-存入localdatatable中 设置 迭代一次 rem SystemUtil.ClosePro ...
- mvc学习过程碰到问题
Fluent API配置 单例模式+Autofac 批量注入