[HEOI2014]逻辑翻译
是道好题
体现了二进制位的形象递归思想,以及将FWT的思路(都是拆位分治)用到题目中的典范
可以暴力高斯消元。完全没有利用2^N以及+-1的良好性质
发现项数,方程和二进制位有关系
考虑类似FWT,FFT能不能递归?


已经具备递归的模式
但是怎样递归下去?
消掉x1的话,对应的位置,1010,0010,相加除以2,相减除以2,分别作为两边递归下去的答案,即可。
这样,通过化简规模,最终到了边界就可以直接得到解。
细节比较多
1.我是+用1,-用0,选择1用1,选择0用0,最后使得项数下标和最后选择的方程下标一致,直接得到答案
2.输出恶心,还是分治。注意别重复输出。其实写的好看一点,本质是线段树的x<<1,x<<1|1
3.读入double,不要强转int,可能是0.999999999999999,所以,x=round(100*df),四舍五入即可。
4.为了卡常,必须快输。
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define numb (ch^'0')
using namespace std;
typedef long long ll;
il void rd(int &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
namespace Miracle{
int n;
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
struct node{
int u,d;
node(){}
node(ll s,ll m){
u=s;d=m;
}
node friend operator +(node a,node b){
return node(a.u+b.u,a.d);
}
node friend operator -(node a,node b){
return node(a.u-b.u,a.d);
}
node friend operator *(node a,ll b){
return node(a.u*b,a.d);
}
node friend operator /(node a,ll b){
return node(a.u,a.d*b);
}
void op(){
if(u<) putchar('-'),u=-u;
int g=gcd(u,d);
u/=g;d/=g;
printf("%d",u);
if(d!=) printf("/%d",d);
}
}c[<<];//,f[1<<20],g[1<<20];
char s[];
void get(){
scanf("%s",s);
int to=;
for(reg i=;i<n;++i){
if(s[i]=='+') to+=(<<i);
}
double df;
scanf("%lf",&df);
c[to].d=;c[to].u=round(df*100.0);
}
void div(int l,int r,int to,int cnt){
if(cnt==n){
//f[to]=c[to];
return;
}
int mid=(l+r)>>;
for(reg i=;i<(<<(n-cnt-));++i){
int t1=(i<<(cnt+))|(to)|(<<cnt);
int t0=(i<<(cnt+))|(to);//|(1<<cnt)
node tmp=c[t1];
c[t1]=(tmp-c[t0])/;
c[t0]=(tmp+c[t0])/;
}
div(l,mid,to,cnt+);
div(mid+,r,to|(<<cnt),cnt+);
}
bool has[<<];
void op(int s){
if(has[s]) return;
has[s]=;
if(c[s].u==) return;
c[s].op();
putchar(' ');
for(reg i=;i<n;++i){
if(s&(<<i)){
printf("x%d",i+);
}
}
puts("");
}
void out(int l,int r,int to,int cnt){
if(cnt==n-){
op(to);op(to|(<<cnt));op(to|(<<cnt)|(<<(cnt+)));op(to|(<<(cnt+)));
return;
}
if(!has[to])op(to);
int mid=(l+r)>>;
out(l,mid,to|(<<cnt),cnt+);
out(mid+,r,to,cnt+);
}
int main(){
rd(n);
for(reg i=;i<(<<n);++i) get();
// for(reg i=0;i<(1<<n);++i){
// cout<<c[i].u<<" "<<c[i].d<<endl;
// }
div(,(<<n)-,,);
if(n==){
op();op();return ;
}
out(,(<<n)-,,);
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
Date: 2019/1/11 19:21:58
*/
[HEOI2014]逻辑翻译的更多相关文章
- [HEOI2014]逻辑翻译(分治)
题目描述 在人类的神经系统中,每个信号都可以用?1或+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 ...
随机推荐
- Selenium2+python自动化-文件上传
前言 文件上传是web页面上很常见的一个功能,自动化成功中操作起来却不是那么简单. 一般分两个场景:一种是input标签,这种可以用selenium提供的send_keys()方法轻松解决:另外一种非 ...
- 第四篇 Postman之Pre-request Script(前置处理器:JS之 YYYY-MM-DD HH:MM:SS)
本篇来讲讲Pre-request Script 前置处理器,定义在发送request之前需要运行的一些脚本,应用场景主要是设置全局变量和环境变量. 本例子也是项目中遇到的,需要修改与客户的预约时间,但 ...
- vue Map 渲染DOM
遍历对象(map),以键值对k:v的形式渲染DOM (1)DOM (2)数据模板
- Spring框架 之IOC容器 和AOP详解
主要分析点: 一.Spring开源框架的简介 二.Spring下IOC容器和DI(依赖注入Dependency injection) 三.Spring下面向切面编程(AOP)和事务管理配置 一.S ...
- centos 7.2 安装apache,mysql,php5.6
安装Apache.PHP.Mysql.连接Mysql数据库的包: yum -y install httpd yum -y install php yum -y install php-fpm yum ...
- python基础知识-01-编码输入输出变量
python其他知识目录 名词解释: 编辑器 ide 程序员 操作系统 ASCAII码 unicode utf-8 浅谈CPU.内存.硬盘之间的关系 操作系统及Python解释器工作原理讲解 关于编译 ...
- Heavy Cargo POJ 2263 (Floyd传递闭包)
Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lat ...
- 互评Alpha版本——二次元梦之队——“I Do”
基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论作品的选题 (1)N(Need,需求) 随着智能科技的发展和普及,编程教育的重要性已经逐渐凸显出来.美国前总统奥巴马曾说“编程应当与 ...
- lintcode-451-两两交换链表中的节点
451-两两交换链表中的节点 给一个链表,两两交换其中的节点,然后返回交换后的链表. 样例 给出 1->2->3->4, 你应该返回的链表是 2->1->4->3. ...
- 【beta】nice!-------约吧NABCD
小组名称:nice! 组长:李权 成员:于淼 刘芳芳韩媛媛 宫丽君 项目内容:约跑app(约吧) 约吧APP下载地址: 百度云:链接:http://pan.baidu.com/s/1jHNBR3g ...