[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 ...
随机推荐
- Eclipse支持文件UTF-8编码
Eclipse修改编码格式_百度经验https://jingyan.baidu.com/article/2009576193ee38cb0721b416.html 这篇最棒 如何为eclipse中的文 ...
- 【学亮IT手记】Servlet的生命周期
1.1 Servlet的生命周期 1.1.1 Servlet的生命周期概述 1.1.1.1 什么是生命周期 生命周期:一个对象从创建到销毁过程. 1.1.1.2 Servlet的生命周期(*****) ...
- 解决ERROR 1130: Host '192.168.11.1' is not allowed to connect to this MySQL
使用navicat进行远程登录MySQL时,报出 ERROR 1130: Host '192.168.11.1' is not allowed to connect to this MySQL se ...
- java的强制类型转换
java强制类型转换 详细连接https://www.cnblogs.com/kuangwong/p/6198862.html 在Java项目的实际开发和应用中,常常需要用到将对象转为String这 ...
- Android——Service介绍与例子
官方定义:Service(服务)是一个没有用户界面的在后台运行执行耗时操作的应用组件.其他应用组件能够启动Service,并且当用户切换到另外的应用场景,Service将持续在后台运行.另外,一个组件 ...
- Saltstack 安装与常用模块
一.介绍 saltstack是基于C/S服务模式,在该架构中,服务器端叫做Master,客户端叫做Minion.传统的C/S模式我们这样理解,客户端发送请求给服务器端,服务器端接受到来自客户端的请求并 ...
- linux查看端口是否开放
在讨论这个问题前,我们先来了解一下物理端口.逻辑端口.端口号等计算机概念. 端口相关的概念: 在网络技术中,端口(Port)包括逻辑端口和物理端口两种类型.物理端口指的是物理存在的端口,如ADSL M ...
- python 编码格式
1. 字符编码简介 1.1. ASCII ASCII(American Standard Code for Information Interchange),是一种单字节的编码.计算机世界里一开始只有 ...
- lr分布式测试--笔记
LR 架构: controller做测试控制 scenario做测试场景的控制 vuser模拟用户和 load generator做负载产生 通过MI listener 跨防火墙监听 来实现分布式测试 ...
- 错误模块名称: KERNELBASE.dll错误
今天在部署一个C/S程序的时候出了bug,日志都没有记载:本地调试当然是没问题的,所以不是代码问题,百度之发现KERNELBASE.dll这个文章说的比较靠谱,仔细研究了自己的配置文件后,果然是配置文 ...