zerosum解题报告
------------------------------------------------------------------------------------------------------------------------------------------------
【题目】
  给你N。
  把1到N依次写出,每相邻两个数字中间加上一个字符,三选一:'+','-',' '。
  如此,便可形成很多表达式,把其中计算结果为0的按字典序输出。
【数据范围】
  3<=N<=9
【输入样例】
  7
【输出样例】
  1+2-3+4-5-6+7
  1+2-3-4+5+6-7
  1-2 3+4+5+6+7
  1-2 3-4 5+6 7
  1-2+3+4-5+6-7
  1-2-3-4-5+6+7
------------------------------------------------------------------------------------------------------------------------------------------------
【分析】
  枚举。脑子清楚,代码别写错就好。
------------------------------------------------------------------------------------------------------------------------------------------------
【总结】
  一遍AC。

------------------------------------------------------------------------------------------------------------------------------------------------

【代码】

 /*
ID: icedrea1
PROB: zerosum
LANG: C++
*/ #include <iostream>
#include <fstream>
using namespace std; int N;
char mark[]; int get(int &l)
{
int r=l;
while(r<N && mark[r]==' ') ++r;
int x=;
for(int i=l;i<=r;++i) x=x*+i;
l=r+;
return x;
} void get(int i,char &c)
{
c=mark[i-];
} void print(ostream& out)
{
for(int i=;i<=N-;++i) out<<i<<mark[i];
out<<N<<endl;
} void test(ostream& out)
{
//cout<<"test: "; print(cout);
int r=;
char c='+';
for(int i=,num=get(i);;num=get(i))
{
if(c=='+') r+=num; else r-=num;
if(i==N+) break; else get(i,c);
}
if(r==) print(out);
} void go(int i,ostream& out)
{
//cout<<i<<endl;
if(i==N) { test(out); return; }
mark[i]=' '; go(i+,out);
mark[i]='+'; go(i+,out);
mark[i]='-'; go(i+,out);
} int main()
{
//printf("%d %d %d\n",'+','-',' '); ifstream in("zerosum.in");
ofstream out("zerosum.out"); in>>N; go(,out); in.close();
out.close();
return ;
}

USACO Section2.3 Zero Sum 解题报告 【icedream61】的更多相关文章

  1. USACO Section2.1 The Castle 解题报告

    castle解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  2. USACO Section2.1 Ordered Fractions 解题报告

    frac1解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...

  3. USACO Section2.1 Healthy Holsteins 解题报告 【icedream61】

    holstein解题报告 --------------------------------------------------------------------------------------- ...

  4. USACO Section2.1 Hamming Codes 解题报告 【icedream61】

    hamming解题报告----------------------------------------------------------------------------------------- ...

  5. USACO Section2.2 Preface Numbering 解题报告 【icedream61】

    preface解题报告----------------------------------------------------------------------------------------- ...

  6. USACO Section2.3 Controlling Companies 解题报告 【icedream61】

    concom解题报告------------------------------------------------------------------------------------------ ...

  7. USACO Section2.3 Money Systems 解题报告 【icedream61】

    money解题报告------------------------------------------------------------------------------------------- ...

  8. USACO Section2.3 Cow Pedigrees 解题报告 【icedream61】

    nocows解题报告------------------------------------------------------------------------------------------ ...

  9. USACO Section2.3 Longest Prefix 解题报告 【icedream61】

    prefix解题报告------------------------------------------------------------------------------------------ ...

随机推荐

  1. windows服务器间文件同步搭建步骤搜集

    Rsync https://www.cnblogs.com/janas/p/3321087.html https://yq.aliyun.com/ziliao/110867 subersion协议 h ...

  2. leetcode: 链表2

    1. copy-list-with-random-pointer(拷贝一个带随机指针的链表) A linked list is given such that each node contains a ...

  3. DFS剪枝,最大团,POJ(1419)

    题目链接:http://poj.org/problem?id=1419 题目大意:一个无向图,用黑白涂色,相邻的两个点不能图同一种颜色,求黑色的点最多有几个? 刚一看题,完全是图的m着色问题啊,我就套 ...

  4. 起一个node服务

    使用node开发一个应用,非常简单,甚至都不用去配置一堆文件来启动一个webu服务器,直接去官网把这一段示例代码拷过来 https://nodejs.org/en/about/ 中文网没有这个abou ...

  5. IOC、注入

    转:https://blog.csdn.net/lutianfeiml/article/details/51731219 实际开发中使用XML还是注解 XML: bean管理 注解: 注入属性的时候比 ...

  6. JS显示上一周

    <html> <head> <script> var currDT; var aryDay = new Array("日","一&qu ...

  7. libtool: Version mismatch error. 解决方法

    在编译一个软件的时候,在 ./configure 和 make  之后可能会出现如下错误: libtool: Version mismatch error.  This is libtool 2.4. ...

  8. H3C S2100配置管理vlan与交换机管理IP

    管理 VLAN 简介:S2100系列以太网交换机任何时刻只能有一个VLAN对应的VLAN接口可以配置IP地址,该 VLAN 即为管理 VLAN.如果要对以太网交换机进行远程管理,必须配置交换机管理 V ...

  9. 2018.9.7 ArrayList

    ArrayList简介 ArrayList核心源码 ArrayList源码分析 System.arraycopy()和Arrays.copyOf()方法 两者联系与区别 ArrayList核心扩容技术 ...

  10. .nettiers和SQLite搅合到一块之后遇到的问题

    第一步 用SQLiteStudio生成一个新的数据库,sqlitetest,新建一张表test,建立一个主键字段ID,一个字符字段Name,建立完成,留待后用. 第二步 用VS2010建立一个sqli ...