您的位置:首页 > 其它

acdream 小晴天老师系列——竖式乘法(简单穷举)

2015-07-16 11:44 344 查看

    小晴天老师系列——竖式乘法

Time Limit: 4000/2000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

小晴天是ACdream团队中最牛的老师之一,他最擅长数学运算~这天他翻开一本《AC is not a dream》杂志,发现最后一页有一道很经典的思维题,题目很简单,每个框填写一个数字,构成一个竖式,每个数的最高位不能为0,但是有一些数字被隐藏掉了,然后让你根据没有隐藏的数字填出隐藏的数字。

如下图:

/*
* this code is made by xcw0754
* Problem: 1704
* Verdict: Accepted
* Submission Date: 2015-07-16 10:18:37
* Time: 4MS
* Memory: 36836KB
*/
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
#define LL long long
#define pii pair<int,int>
#define INF 0x7f7f7f7f
using namespace std;
const int N=500005;
int up;
int s
[18];

void pre_cal()
{
up=0;
for(int i=100; i<1000; i++)
{
for(int j=10; j<100; j++)
{
s[up][0]=i/100; //不能为0
s[up][1]=i/10%10;
s[up][2]=i%10;

s[up][3]=j/10;  //不能为0
s[up][4]=j%10;

int tmp=i*(j%10);   //第3行
s[up][5]=tmp/1000;  //不能为0
if(!s[up][5] || s[up][5]>9)  continue;
s[up][6]=tmp/100%10;
s[up][7]=tmp/10%10;
s[up][8]=tmp%10;

tmp=i*(j/10);       //第4行
s[up][9]=tmp/100;   //不能为0
if(!s[up][9]|| s[up][9]>9)  continue;
s[up][10]=tmp/10%10;
s[up][11]=tmp%10;

tmp=i*j;            //第5行
s[up][12]=tmp/10000;//不能为0
if(!s[up][12])  continue;
s[up][13]=tmp/1000%10;
s[up][14]=tmp/100%10;
s[up][15]=tmp/10%10;
s[up][16]=tmp%10;
up++;
}
}

}

int now[18];
vector<int> alk;
char c[18];

void get_input()
{
memset(now,0,sizeof(now));
alk.clear();

scanf("%s",c);
scanf("%s",c+3);
scanf("%s",c+5);
scanf("%s",c+9);
scanf("%s",c+12);

for(int i=0; i<17; i++)
if(isdigit(c[i]))
{
now[i]=c[i]-'0';
alk.push_back(i);
}
}

int cal()
{
int ans=0;
for(int i=0; i<up; i++)
{
int j;
for(j=0; j<alk.size(); j++) //这几个都要匹配
{
int k=alk[j];
if(now[k]!=s[i][k]) break;
}
if(j==alk.size())
ans++;
}
return ans;
}

int main()
{
//freopen("input.txt", "r", stdin);
pre_cal();
int t;
scanf("%d",&t);
while(t--)
{
get_input();
printf("%d\n",cal());
}
return 0;
}


AC代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: