记录编号 |
114520 |
评测结果 |
AAAAAAA |
题目名称 |
[USACO 2.3.3]零数列 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.002 s |
提交时间 |
2014-07-31 13:32:11 |
内存使用 |
0.31 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
int n;
char ch[20];
//==============function declaration============
void dfs(int depth);
bool check();
void print();
//==============main code=======================
int main()
{
freopen("zerosum.in","r",stdin);
freopen("zerosum.out","w",stdout);
cin>>n;
dfs(1);
return 0;
}
//================fuction code====================
void dfs(int depth)
{
if (depth==n)
{
if (check())
print();
return ;
}
ch[depth]=' ';
dfs(depth+1);
ch[depth]='+';
dfs(depth+1);
ch[depth]='-';
dfs(depth+1);
return;
}
bool check()
{
int sum=0;
int now=0;
int mul=1;
ch[n]='+';
For(i,1,n)
{
now=now*10+i;
if (ch[i]!=' ')
{
sum+=mul*now;
now=0;
if (ch[i]=='+')
mul=1;
else if (ch[i]=='-')
mul=-1;
}
}
return (sum==0);
}
void print()
{
For(i,1,n-1)
pritnf("%d%c",i,ch[i]);
printf("%d\n",n);
}