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代码
相关文章推荐
- Linux汇编与C互相调用
- Classloader工作机制
- VS常用快捷键一览表
- linux中shell变量$#,$@,$*,$?,$0,$1,$2的含义解释
- interllij IDEA scala报错
- 基本jquery
- DIV悬浮在页面底部或头部
- Square:从今天开始抛弃Fr 4000 agment吧!
- java 注解:SuppressWarnings、Deprecated、Override
- 中文分词解析
- linux shell if 参数
- hdu 1251 统计难题(字典树)
- 【ACM】-斐波那契数列 -- 递归并不一定就是好
- hadoop集群环境的搭建
- [leedcode 88] Merge Sorted Array
- 关于Entity Framework中的Attached报错的完美解决方案终极版
- js实现下拉框‘省’,‘市’加载
- Objective-C之内存管理
- WCF_通过使用svcutil.exe将http://*.svc?wsdl生成客户端可调用的.cs文件
- Windows下JAVA用到的环境变量主要有3个,JAVA_HOME、CLASSPATH、PATH。