[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 ...
随机推荐
- eclipse集成testng插件(离线安装方式)
testng是一个优秀的测试框架,我们在开发自动化测试脚本或者框架的时候经常会用到这个框架,因为它不仅能方便的帮助我们管理测试类,而且它还提供了丰富的注解来支持各种测试场景的实现(参数化,数据提供者, ...
- JUC——JUC开发简介(一)
前言 JUC是Java5.0开始提供的一组专门实现多线程并发处理的开发框架,利用JUC开发架构可以有效的解决实际线程项目开发之中出现的死锁.阻塞.资源访问与公平机制. 此笔记主要记录java.util ...
- mysql5.5 升级到 5.7 的坑
1.大概思路,docker 新启一个mysql5.7 端口映射到3307 2. 导出5.5 的.sql文件,导入5.7中 3.测试通过后,可将5.5关闭.5.7端口改回3306 GRANT ALL P ...
- Pearson Distance
Pearson Distance: where: 1. is the covariance 2. is the standard deviation of 3. is the standard ...
- leetcode个人题解——#39 Combination Sum
思路:先对数据进行排序(看评论给的测试数据好像都是有序数组了,但题目里没有给出这个条件),然后回溯加剪枝即可. class Solution { public: ; vector<vector& ...
- 3.Airflow使用
1. airflow简介2. 相关概念2.1 服务进程2.1.1. web server2.1.2. scheduler2.1.3. worker2.1.4. celery flower2.2 相关概 ...
- 第八次作业psp
psp 进度条 代码累积折线图 博文累积折线图 psp饼状图
- Thunder--Beta发布--美工+文案
作业:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1366 内容: 美工:原有功能展示.新增功能展示 程序图标 欢迎页面 我的书架 ...
- 【Alpha】阶段第五次Scrum Meeting
[Alpha]阶段第五次Scrum Meeting 工作情况 团队成员 今日已完成任务 明日待完成任务 刘峻辰 增加课程接口 增加教师接口 赵智源 整合前端进行部署 构建后端测试点测试框架 肖萌威 编 ...
- 《Linux内核与分析》第五周
20135130王川东 一.给MenuOS增加time和time-asm命令 命令:1.强制删除:rm menu -rf 2.克隆:git clone (后跟需要克隆数据所在的位置) 3.自动编译,自 ...