HDU5100Chessboard(数论)

题目链接

题目大意:用k∗1的瓷砖区铺n∗n的矩形,问能铺上的最大的面积。

解题思路:这题没有直接得出结论:l = n%k, ans = max[(n^2 - l^2), (n^2 - (k - l)^2)],可是在画的过程中发现了。最好的情况就仅仅有两种铺法。要不依照贪心的策略来铺,直到铺不下为止。或者是一圈一圈的铺。铺完一圈后最后还会剩下一个矩形。然后再递归子问题,每一个子问题都是返回面积最大的。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int find (int n, int k) { if (n < k)
return 0;
int mul = n / k;
int mod = n % k;
return (mul * n + mod * mul) * k;
} int solve (int n, int k) { int tmp1 = find(n, k), tmp2 = 0; if (n > k && n % k)
tmp2 = solve(n - 2 * (n % k), k) + 4 * (n / k) * (n % k) * k;
return max(tmp1, tmp2);
} int main () { int T, N, K;
scanf ("%d", &T);
while (T--) { scanf ("%d%d", &N, &K);
printf ("%d\n", solve(N, K));
}
return 0;
}

HDU5100Chessboard(数论)的更多相关文章

  1. Codeforces Round #382 Div. 2【数论】

    C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...

  2. NOIP2014 uoj20解方程 数论(同余)

    又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...

  3. 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)

    ~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...

  4. hdu 1299 Diophantus of Alexandria (数论)

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  5. 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)

    4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status ...

  6. bzoj2219: 数论之神

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  7. hdu5072 Coprime (2014鞍山区域赛C题)(数论)

    http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...

  8. ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德

    POJ 1061 青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu  Descr ...

  9. 数论初步(费马小定理) - Happy 2004

    Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...

随机推荐

  1. UVA 11737 Extreme Primitive Society

    非常容易的一个题: 只要判断两种基因相差的最小值就行: #include<cstdio> #include<cstring> #include<algorithm> ...

  2. *[codility]StoneWall

    https://codility.com/demo/take-sample-test/stone_wall 拼石块.用最少的方块.一开始想了想用贪心,是可行的,就是尽量每次把当前的高度往右延伸到最多, ...

  3. JavaWeb学习总结(三十五)——使用JDBC处理Oracle大数据

    一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...

  4. 怎样在WINDOWS下面编译LIBCURL

    我测试过,好像没OK This is a short note about building cURL with SSL support on Windows. Tools required: cUR ...

  5. float 和 real

      用于表示浮点数值数据的大致数值数据类型.浮点数据为近似值:因此,并非数据类型范围内的所有值都能精确地表示. 注意: real 的 SQL-92 同义词为 float(24). 数据类型 范围 存储 ...

  6. int指令理解

    以下是王爽老师的<汇编语言>中第十五章中的一段程序代码,其功能是增加9号中断的功能,当按下Esc键时屏幕中显示的字母改变颜色 assume cs:codesg,ss:stack,ds:da ...

  7. Yii CDbCriteria

    Yii的Active Recorder包装了很多. 特别是把SQL中 把where,order,limit,IN/not IN,like等常用短句都包含进CDbCriteria这个类中去,这样整个代码 ...

  8. Covariance and Contravariance in C#, Part Two: Array Covariance

    http://blogs.msdn.com/b/ericlippert/archive/2007/10/17/covariance-and-contravariance-in-c-part-two-a ...

  9. 为什么你的 phpinfo() 无法显示

    一.问题描述 编写了一个php文件test.php,代码如下: <?php echo phpinfo(); ?> 浏览器访问了一下,却返回了 NULL. 二.问题定位及解决 网上查了下,大 ...

  10. Apache ‘mod_pagespeed’模块跨站脚本漏洞

    漏洞名称: Apache ‘mod_pagespeed’模块跨站脚本漏洞 CNNVD编号: CNNVD-201310-677 发布时间: 2013-11-05 更新时间: 2013-11-05 危害等 ...