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

44 篇文章 0 订阅
23 篇文章 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根火柴棍必须全部用上

Image:Noip08match.jpg

 

题目思路:

  【枚举】

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

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

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

 

//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) (a)*(a)
#define swap(a,b) (a)^=(b),(b)^=(a),(a)^=(b)
#define eps 1e-8
#define S 10000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 34
#define M 1111
using namespace std;
int n,m,cas,lll,ans;
int a[4];
int r[10]={6,2,5,5,4,5,6,3,7,6};
int cal(int aa)
{
	cas=0;
	if(aa==0)return 6;
	for(cas=0;aa;aa/=10)
		cas+=r[aa%10];
	return cas;
}
void work()
{
	int i,j,x,y,z;
	for(i=0;i<M;i++)
	{
		x=cal(i);
		if(x>=n-1)continue;
		z=cal(i+i);
		if(x+x+z==n)
		{
			ans++;
			//printf("%d+%d=%d\n",i,i,i+i);
		}
		for(j=i+1;j<=M;j++)
		{
			y=cal(j);
			if(x+y>=n-1)continue;
			z=cal(i+j);
			if(x+y+z==n)
			{
				ans+=2;
				//printf("%d+%d=%d\n",i,j,i+j);
			}
		}
	}
}
int main()
{
	#ifndef ONLINE_JUDGE
//	freopen("1.txt","r",stdin);
//	freopen("2.txt","w",stdout);
	#endif
	int i,j,k;
//	while(~scanf("%s",s))
	while(~scanf("%d",&n) && n)
	{
		ans=0;
		n-=4;
		work();
		printf("%d\n",ans);
	}
	return 0;
}


/*
//

//
*/


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值