ywy_c_asm的良心题解

是道好题

体现了二进制位的形象递归思想,以及将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]逻辑翻译的更多相关文章

  1. [HEOI2014]逻辑翻译(分治)

    题目描述 在人类的神经系统中,每个信号都可以用?1或+1来表示.这些信号组合起来最后形成 了喜怒哀乐,酸甜苦辣,红黄绿蓝等各种各样的复杂信息.纳米探测科技的突破让生物学家 可以测量大脑中特定区域的完整 ...

  2. 洛谷 4106 / bzoj 3614 [HEOI2014]逻辑翻译——思路+类似FWT

    题目:https://www.luogu.org/problemnew/show/P4106 https://www.lydsy.com/JudgeOnline/problem.php?id=3614 ...

  3. 【Moqui业务逻辑翻译系列】Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和机会

    h1. Sales Representative Seeks Prospects and Opportunities 销售代表寻找期望合作对象和合作机会 h4. Ideas to incorporat ...

  4. 【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 ...

  5. 【Moqui业务逻辑翻译系列】Story of Online Retail Company 在线零售公司的故事

    h1. Story of Online Retail Company 在线零售公司的故事 Someone decides to sell a product. [Product Marketer Ma ...

  6. 【Moqui业务逻辑翻译系列】--UBPL index

    h2. [UBPL Introduction] ubpl介绍h2. [Actor Definitions] 行为定义h2. General Business Process Stories 通常的商业 ...

  7. 【Moqui业务逻辑翻译系列】--UBPL Introduction同意的商业处理文库介绍

    h1. UBPL Introduction 通用的商业处理文库介绍h4. Why a Universal Business Process Library? 为什么需要通用的商业处理文库? The g ...

  8. 洛谷 P4106 / bzoj 3614 [ HEOI 2014 ] 逻辑翻译 —— 思路+递归

    题目:https://www.luogu.org/problemnew/show/P4106 https://www.lydsy.com/JudgeOnline/problem.php?id=3614 ...

  9. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

随机推荐

  1. Sublime Text3添加右键

    在Sublime Text3安装目录下新建一个文件 sublime_addright.inf 文件内容: [Version] Signature="$Windows NT$" [D ...

  2. spark重点知识

    1 scala 2 spark rdd 3 sprak core 4 性能优化 5 spark sql 6 spark streaming 掌握程度-精通的理解:

  3. leetcode-下一个排列

    下一个排列 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列. 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排列). 必须原地修改,只允许使用额外 ...

  4. python程序设计——面向对象程序设计:继承

    继承是为代码复用和设计复用而设计的 在继承关系中,已有的.设计好的类称为父类或基类,新设计的类为子类或派生类 派生类可以继承父类的公有成员,但不能继承其私有成员 如果需要在派生类中调用基类的方法,可以 ...

  5. K8S-RedisCluster搭建

    简介         Redis-Cluster采用无中心结构,每个节点保存数据和整个集群状态,每个节点都和其他所有节点连接, mastart节点之间存放的数据并不是相同的,只是其中的一部分,当我们请 ...

  6. java之接口开发-初级篇-webservice协议

    webservice协议 客户端: 客户端生成使用soapUI生成 外部提供webservice地址,地址后加?wsdl.选择好目录然后生成,放到项目中实现 服务端: web.xml平级目录下创建se ...

  7. 自然语言处理 - 如何通俗地理解TFIDF?

    本博客属个人学习笔记,如有疏漏,欢迎在评论留言指出~转载请注明. 在自然语言处理中,TFIDF常常被人提及.很多材料都提及TFIDF中的“普遍重要性”,但很少有材料去简单解释其中的原理.TFIDF其实 ...

  8. scrapy-redis+selenium+webdriver 部署到linux上

    背景:在使用selenium时,在本地使用windows,都会有一个图形界面,但是到了生产环境linux上没有了图形界面怎么部署呢? 解决方案: 1.安装图形化界面,不推荐,因为安装图形化界面会占用很 ...

  9. PS1修改xshell命令行样式

    linux 其他知识目录 在/root/.bashrc下加入如下代码. export PS1='\n\e[1;37m[\e[m\e[1;32m\u\e[m\e[1;33m@\e[m\e[1;35m\H ...

  10. 欢迎来怼—第二次Scrum会议

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华小组照片 二.开会信息 时间:2017/10/14 18:30~18:47,总计17min.地点:东北师范 ...