*dessert<pku 1950>

 
  
 /* 虽然很简单,但也花了我不少时间debug,本来定义了全局变量t,但在main函数中又定义了一次,导致各种不对,调试居然发现
  t == -1,才发现这个错误,还有处理的时候,基本上是想到什么就添加什么条件,没有一个整体的解题思路,属于乱砍型,还是要
在编代码的时候,把思路全理清楚再去敲代码,这样效率应该会高些. */
1 Source Code
2
3 Problem: 1950 User: eth1
4 Memory: 248K Time: 125MS
5 Language: C ++ Result: Accepted
6 Source Code
7 #include < iostream >
8 #include < cstring >
9 using namespace std;
10 int t,count;
/
12 char ans[ 20 ];
13 void solve( int a, int sum, int tt, int tem)
14 {
15 if (a == t - 1 )
16 {
17 if (sum == 0 )
18 {
19 if (count < 20 ){
20 cout << " 1 " ;
21 for ( int i = 0 ;i < t - 1 ;i ++ )
22 {
23 cout << " " << ans[i] << " " << i + 2 ;
24 }
25 cout << endl;
26 }
27 count ++ ;
28 }
29 return ;
30 }
31 ans[a] = ' + ' ;
32 solve(a + 1 ,sum + tt,tt + 1 ,tt);
33 ans[a] = ' - ' ;
34 solve(a + 1 ,sum - tt,tt + 1 , - tt);
35 ans[a] = ' . ' ;
36 int k = tem;
37 if (tt >= 10 ){
38 if (tem < 0 ) tem = - (( - tem) * 100 + tt);
39 else tem = tem * 100 + tt;
40 }
41 else {
42 if (tem < 0 ) tem = - (( - tem) * 10 + tt);
43 else tem = tem * 10 + tt;
44 }
45 solve(a + 1 ,sum - k + tem,tt + 1 ,tem);
46 return ;
47 }
48 int main()
49 {
50 cin >> t;
///
52 count = 0 ;
53 solve( 0 , 1 , 2 , 1 );
54 cout << count << endl;
55 return 0 ;
56 }

转载于:https://www.cnblogs.com/eth0/archive/2011/05/10/2042087.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值