2015 EC L - Multiplication Table
/*************************************************************************
> File Name: L.cpp
> Author: LyuCheng
> Created Time: 2017-12-03 17:31
> Description:
题意:首先有一个乘法表,然后给你一个n*m的矩阵,里面有不确定的数,然
后问你,这个表可不可能是乘法表的一部分 思路:暴力判断每个点
************************************************************************/ #include <bits/stdc++.h> #define MAXN 1234
#define MAXM 12
#define LL long long using namespace std; struct Point{
int x,y;
LL val;
Point(){}
Point(int _x,int _y,LL _val){
x=_x;
y=_y;
val=_val;
}
}; int t;
int n,m;
LL mapn[MAXN][MAXN];
char str[MAXM];
bool flag;
vector<Point>P; inline LL cal(char str[]){
int len=strlen(str);
LL s=;
for(int i=;i<len;i++){
s*=;
s+=str[i]-'';
}
return s;
} inline bool judge(LL x,LL y,LL fx,LL fy){
for(int i=;i<(int)P.size();i++){
if((fx+P[i].x-x)*(fy+P[i].y-y)!=P[i].val)
return false;
}
return true;
} inline void init(){
P.clear();
flag=false;
} int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int ca=;ca<=t;ca++){
printf("Case #%d: ",ca);
init();
scanf("%d%d",&n,&m);
for(LL i=;i<=n;i++){
for(LL j=;j<=m;j++){
scanf("%s",str);
if(str[]!='?'){
mapn[i][j]=cal(str);
P.push_back(Point(i,j,mapn[i][j]));
}else{
mapn[i][j]=;
}
}
}
if((int)P.size()==){
puts("Yes");
}else {
for(LL i=;i*i<=P[].val;i++){
if(P[].val%i==){
LL fx=i;
LL fy=P[].val/i;
if(fx>=P[].x&&fy>=P[].y)
if(judge(P[].x,P[].y,fx,fy)==true){
flag=true;
break;
}
swap(fx,fy);
if(fx>=P[].x&&fy>=P[].y)
if(judge(P[].x,P[].y,fx,fy)==true){
flag=true;
break;
}
}
}
puts(flag==true?"Yes":"No");
}
}
return ;
}
2015 EC L - Multiplication Table的更多相关文章
- UVALive 7511 L - Multiplication Table 数学模拟题,暴力
给定一副表,问其是否合法. 思路:当全部是?的时候,是合法的. 如果不是,那么,就找到一个数字,把它拆成若干个a*b的形式,去判断其它点是否合法即可. 拆分数字的时候,只需要枚举到sqrt(n),因为 ...
- cf448D Multiplication Table
D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)
转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table 二分法
D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input st ...
- Codeforces 448 D. Multiplication Table 二分
题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...
- 668. Kth Smallest Number in Multiplication Table
Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...
- LeetCode hard 668. Kth Smallest Number in Multiplication Table(二分答案,一次过了,好开心,哈哈哈哈)
题目:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/ 668. Kth S ...
- 洛谷 CF448D Multiplication Table
目录 题目 思路 \(Code\) 题目 CF448D Multiplication Table 思路 二分答案.这个矩阵的每一排都是递增的,所以二分\(ans\),去计算有多少个数等于\(ans\) ...
- Day8 - D - Multiplication Table CodeForces - 448D
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the mu ...
随机推荐
- KubeCon深度洞察 | KubeEdge开源首秀
以下内容根据华为云DJ在KubeCon Shanghai Demo Session演讲实录整理而成. KubeEdge Demo Show 11月15日上午Huawei宣布了KubeEdge项目开源, ...
- Java多线程之volatile与synchronized比较
可见性: JAVA内存模型: java为了加快程序的运行效率,对一些变量的操作是在寄存器或者CPU缓存上进行的,后面再同步到主存中 看上图,线程在运行的过程中,会从主内存里面去去变量,读到自己的空间内 ...
- Linux命令应用大词典-第46章 其他命令
46.1 mkfontdir:创建X字体文件的索引 46.2 dumpiso:转储IEEE 1394同步信道的数据包 46.3 iconv:转换文件编码 46.4 hash:显示和删除哈希表 46.5 ...
- 域名、IP地址、URL关系
域名是个文字形式记录的IP地址 IP地址是计算机在网络中的门牌号! URL是网页地址 例如1: http://zhidao.baidu.com/question/14674128.html 是URL ...
- 如何处理 jQuery $(window).resize() 中的方法被多次执行的小问题
引言: 估计很多同志们在编写浏览器resize()的方法时,都会遇到这样的情况: 当拖动浏览器的边角时,页面中的一些效果随浏览器大小的改变而触发,这一过程开始到结束,resize() 中的方法被执行了 ...
- Java Web开发框架Spring+Hibernate整合效果介绍(附源码)(已过期,有更好的)
最近花了一些时间整合了一个SpringMVC+springAOP+spring security+Hibernate的一套框架,之前只专注于.NET的软件架构设计,并没有接触过Java EE,好在有经 ...
- [Clr via C#读书笔记]Cp17委托
Cp17委托 简单介绍 delegate回调函数机制,可以理解存储函数地址的变量类型: 类型安全: 引用类型支持逆变和协变: 回调 静态方法,实例方法 委托的本质 所有的委托都派生自System.Mu ...
- POJ 3384 Feng Shui(计算几何の半平面交+最远点对)
Description Feng shui is the ancient Chinese practice of placement and arrangement of space to achie ...
- Python练习——循环2
1.求1~100之间能被7整除,但不能同时被5整除的所有整数 . for i in range(1,101): if i%7 == 0 and i%5 !=0: print(i) 2.输出“水仙花数” ...
- SDUST OJ 时间类的加、减法赋值运算
Problem F: 时间类的加.减法赋值运算 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 3801 Solved: 2210[Submit][St ...