给定一副表,问其是否合法。

思路:当全部是?的时候,是合法的。

如果不是,那么,就找到一个数字,把它拆成若干个a*b的形式,去判断其它点是否合法即可。

拆分数字的时候,只需要枚举到sqrt(n),因为肯定是两个小于sqrt n的数相乘得到的结果。

比如6=1*6 6=2*3 注意分解后,考虑调换顺序是否合法即可。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> const int maxn = +;
struct data
{
LL num;
int flag;
} a[maxn][maxn];
struct coor
{
int x,y;
LL num;
} To_number[maxn*maxn];
int len_To_number;
int n,m;
void show ()
{
for (int i=; i<=n; ++i)
{
for (int j=; j<=m; ++j)
{
if (a[i][j].flag)
printf ("%I64d ",a[i][j].num);
else printf ("? ");
}
printf ("\n");
}
return ;
}
int f;
int solve (int x,int y,LL num)
{
LL end = (LL)sqrt(num+0.5);
for (LL aa=; aa<=end; ++aa)
{
if (num%aa != ) continue;
LL bb = num/aa;//公差是aa
int k;
if (aa>=x && bb>=y)
{
for (k=; k<=len_To_number; ++k)
{
int tx = To_number[k].x - x;
int ty = To_number[k].y - y;
LL ta = aa+tx, tb = bb+ty;
if (ta*tb != To_number[k].num) break;
}
if (k == len_To_number +) return ;
}
LL taa = aa;
LL tbb = bb;
swap(taa,tbb);
//cout<<taa<<" "<<tbb<<"--"<<endl;
if (taa>=x && tbb >= y)
{
for (k=; k<=len_To_number; ++k)
{
int tx = To_number[k].x - x;
int ty = To_number[k].y - y;
LL ta = taa+tx, tb = tbb+ty;
if (ta*tb != To_number[k].num) break;
}
if (k == len_To_number +) return ;
}
}
return ;
}
void work ()
{
int allque = ;
scanf("%d%d",&n,&m);
int bx,by;
LL number;
len_To_number = ;
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
{
char str[];
scanf("%s",str+);
if (str[]=='?') a[i][j].flag = ;
else
{
allque = ;
a[i][j].flag=;
int lenstr = strlen(str+);
a[i][j].num=;
for (int k=; k<=lenstr; ++k)
a[i][j].num = a[i][j].num*+str[k]-'';
bx=i;
by=j;
number=a[i][j].num;
To_number[++len_To_number].num = a[i][j].num;
To_number[len_To_number].x = i;
To_number[len_To_number].y = j;
}
}
//show();
if (allque)
{
printf ("Case #%d: Yes\n",++f);
return ;
}
if (solve(bx,by,number))
{
printf ("Case #%d: Yes\n",++f);
return ;
}
else
{
printf ("Case #%d: No\n",++f);
return ;
}
} int main()
{
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
scanf("%d",&t);
while (t--) work();
return ;
}

另外,枚举两个点的话,满足这两个点的解,就是唯一的解。也可以枚举两个点,然后确定唯一的一个解,再去比较整个地图。

不过也没什么必要。速度差不多。因为很少这样的例子,使得枚举的时候有很多个数字是满足的。

UVALive 7511 L - Multiplication Table 数学模拟题,暴力的更多相关文章

  1. Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题

    A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...

  2. 2015 EC L - Multiplication Table

    /************************************************************************* > File Name: L.cpp > ...

  3. HDU 4951 Multiplication table 阅读题

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4951 题意:给一个P进制的乘法表.行和列分别代表0~p-1,第i行第j*2+1和第j*2+2列代表的是第i ...

  4. Codeforces 448 D. Multiplication Table 二分

    题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...

  5. cf448D Multiplication Table

    D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. LeetCode hard 668. Kth Smallest Number in Multiplication Table(二分答案,一次过了,好开心,哈哈哈哈)

    题目:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/ 668. Kth S ...

  7. hdu4951 Multiplication table (乘法表的奥秘)

    http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...

  8. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

  9. 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 ...

随机推荐

  1. easy_install下载地址及安装

    下载地址 https://pypi.python.org/pypi/setuptools 解压 tar -xzvf xx.tar.gz 安装 cd 解压目录 sudo python setup.py ...

  2. 资料:MVC框架+SQL Server 数据集成引擎

    ylbtech-资料:MVC框架+SQL Server 数据集成引擎 1.返回顶部 1. 功能特点: MVC框架耦合性低视图层和业务层分离,这样就允许更改视图层代码而不用重新编译模型和控制器代码,同样 ...

  3. windows修改远程桌面RDP连接数

    windows 2003在默认情况下最多只允许两个用户进行远程终端连接,当达到两个远程桌面连接的到时候,再有人尝试连接,就会提示已经达到最大终端数,无法连上了. 一.windows2003终端连接数修 ...

  4. IIS及时回收

    在打开的列表中更改以下设置:回收——固定时间间隔(分钟) 改为 0进程模型——闲置超时(分钟) 改为 0

  5. 3DES加密/解密

    /// <summary> /// C#/PHP/JSP 3DES 加密与解密(只支持UTF-8编码) /// </summary> public class Crypto3D ...

  6. 每天一道算法题(4)——O(1)时间内删除链表节点

    1.思路 假设链表......---A--B--C--D....,要删除B.一般的做法是遍历链表并记录前驱节点,修改指针,时间为O(n).删除节点的实质为更改后驱指针指向.这里,复制C的内容至B(此时 ...

  7. 微信小程序报错.wxss无法找到

    小程序原来一直运行正常,编译都没有问题,但今天更新了一下工具,就一直编译不过,报.wxss无法找到,搜索半天,才解决. 解决方案如下: 在控制台输入openVendor(), 在打开的目录中清除wcs ...

  8. 22、IDP-ASE

    IDPASE https://github.com/bdeonovic/IDPASE.jl Prepare necessary input files (1)FASTQ file of your hy ...

  9. .NET 中文件嵌套,例如:cshtml文件下面嵌套css和js【机器翻译】

    越来越多的我发现自己在我的一些较大的Web项目中丢失了文件.有很多内容要处理 - HTML视图,几个派生CSS页面,页面级CSS,脚本库,应用程序范围的脚本和页面特定的脚本文件等等.幸运的是,我使用R ...

  10. mysql 索引总结

    一.MYSQL索引类型(共三种) 1).normal 正常 应用场景:普通的index 2).unique 唯一性的 应用场景:比如身份证的 3).full text 全文索引 应用场景:较长文字 二 ...