[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 ...
随机推荐
- Halcon学习网
重码网是一个在线机器视觉学习网站,推出了Halcon,Visionpro机器视觉学习视频教程,视频内容通俗易懂,没有编程基础的同学,照着视频练习,也同样可以学会. 学机器视觉,拿高薪,成就技术大拿.重 ...
- 清空git缓存
git rm -r --cached .git add . git commit -m 'update .gitignore' 读了下git文档,才发现,这些东西其实很简单,很容易理解.cached其 ...
- linux 性能分析命令及其解释
很多时候,我们需要对linux上运行的环境大体有一个了解,那么久需要大体知道当前系统的相关资源的使用情况,那么可以用一些linux提供的丰富的命令来查看 性能分析 vmstat 虚拟内存统计 用法 U ...
- iPhone上的CPU架构,核数以及运行内存
机型 CPU架构 CPU名 CPU位数 CPU核数 运行内存 iPhone 5 ARMv7s A6 32bit 双核 1G iPhone 5c ARMV7s A6 32bit 双核 1G iPhone ...
- 王者荣耀交流协会第四次Scrum立会
会议时间:2017年10月23号 18:00-18:28,时长28分钟. 会议地点:二食堂一楼第四个档口对着的靠路边的桌子. 立会内容: 1.小组成员汇报今日工作: 2.关于折线图与饼状图生成问题 ...
- 暑假App
简介 实现了一个计时器APP,程序界面简洁,只有一个时间显示区域和两个图片按钮,一个按钮是开始/暂停,另一个按钮是停止. 功能介绍 一个显示界面,当最小计时单位为0.1秒时,显示为:分钟:秒:0.1秒 ...
- Apache 的知识点
apache 的官方文档 http://httpd.apache.org/docs/ Mac下如何查看Apache的版本 在终端(Terminal)中输入 apachectl -v,之后回车,结果如下 ...
- 【Leetcode】725. Split Linked List in Parts
Given a (singly) linked list with head node root, write a function to split the linked list into k c ...
- [历史百科]抗战时期兵团简介 From 百度知道
中央军委1948年11月1日和1949年1月15日两次关于统一全军组织和部队番号的训令,我军先后进行了整编.西北野战军改称第一野战军,司令员兼政治委员彭德怀,第一副司令员张宗逊,第二副司令员赵寿山,参 ...
- SpingCloud之feign框架调用
1.生产者(没有什么特殊性) pom.xml <?xml version="1.0" encoding="UTF-8"?> <project ...