码迷,mamicode.com
首页 > 其他好文 > 详细

Vijos P1496 火柴棒等式 【NOIP2008提高组第二题】

时间:2016-03-23 06:19:11      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:https://vijos.org/p/1496

题目大意:

  给你n(n<24)根火柴棍,你可以拼出多少个形如“A+B=C”的等式?("+"和"="各自需要两根火柴棍)

  如果A≠B,则A+B=C与B+A=C视为不同的等式(A、B、C>=0)

  n根火柴棍必须全部用上

技术分享

 

题目思路:

  其实这题很水,n最大才24,扣掉+和=就只有20,直接枚举就行。

  稍微算一下就知道每个数最大不会超过1111

  两层for枚举每个数,判断是否用尽火柴即可。

 

技术分享
 1 //
 2 //by coolxxx
 3 //
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<memory.h>
 9 #include<time.h>
10 #include<stdio.h>
11 #include<stdlib.h>
12 #include<string.h>
13 #include<stdbool.h>
14 #include<math.h>
15 #define min(a,b) ((a)<(b)?(a):(b))
16 #define max(a,b) ((a)>(b)?(a):(b))
17 #define abs(a) ((a)>0?(a):(-(a)))
18 #define lowbit(a) (a&(-a))
19 #define sqr(a) (a)*(a)
20 #define swap(a,b) (a)^=(b),(b)^=(a),(a)^=(b)
21 #define eps 1e-8
22 #define S 10000
23 #define MAX 2139062143
24 #define PI 3.1415926535897
25 #define N 34
26 #define M 1111
27 using namespace std;
28 int n,m,cas,lll,ans;
29 int a[4];
30 int r[10]={6,2,5,5,4,5,6,3,7,6};
31 int cal(int aa)
32 {
33     cas=0;
34     if(aa==0)return 6;
35     for(cas=0;aa;aa/=10)
36         cas+=r[aa%10];
37     return cas;
38 }
39 void work()
40 {
41     int i,j,x,y,z;
42     for(i=0;i<M;i++)
43     {
44         x=cal(i);
45         if(x>=n-1)continue;
46         z=cal(i+i);
47         if(x+x+z==n)
48         {
49             ans++;
50             //printf("%d+%d=%d\n",i,i,i+i);
51         }
52         for(j=i+1;j<=M;j++)
53         {
54             y=cal(j);
55             if(x+y>=n-1)continue;
56             z=cal(i+j);
57             if(x+y+z==n)
58             {
59                 ans+=2;
60                 //printf("%d+%d=%d\n",i,j,i+j);
61             }
62         }
63     }
64 }
65 int main()
66 {
67     #ifndef ONLINE_JUDGE
68 //    freopen("1.txt","r",stdin);
69 //    freopen("2.txt","w",stdout);
70     #endif
71     int i,j,k;
72 //    while(~scanf("%s",s))
73     while(~scanf("%d",&n) && n)
74     {
75         ans=0;
76         n-=4;
77         work();
78         printf("%d\n",ans);
79     }
80     return 0;
81 }
82 
83 
84 /*
85 //
86 
87 //
88 */
View Code

 

Vijos P1496 火柴棒等式 【NOIP2008提高组第二题】

标签:

原文地址:http://www.cnblogs.com/Coolxxx/p/5309362.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!