HDU5100Chessboard(数论)
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(数论)的更多相关文章
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- NOIP2014 uoj20解方程 数论(同余)
又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...
- 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)
~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)
4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 290 Solved: 148[Submit][Status ...
- bzoj2219: 数论之神
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- hdu5072 Coprime (2014鞍山区域赛C题)(数论)
http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...
- ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德
POJ 1061 青蛙的约会 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Descr ...
- 数论初步(费马小定理) - Happy 2004
Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...
随机推荐
- Android编程中常用的PopupWindow和Dialog对话框
注意:PopupWindow组件的使用问题,PopupWindow是一个阻塞对话框,如果你直接在Activity创建的方法中显示它,则会报错:android.view.WindowManager$Ba ...
- 简单的Ajax例子
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- win7桌面图标小盾牌怎么去掉(2种方法)
很多用户都会在桌面上放置一些常用的程序图标,由于win7系统提高了系统安全性,新增用户帐户控制,所以会在图标上显示小盾牌,表示需要管理员权限打开.不少win7 32位旗舰版用户觉得这个小盾牌很碍眼,那 ...
- C 语言函数指针
c代码: #include <stdio.h> int add(int x,int y); int subtract(int x,int y); int domath(int (*math ...
- ruby mysql数据库操作
require 'mysql' con=Mysql.new('localhost','root','root','test') con.query('set names utf8') rs=con.q ...
- 1uboot移植要点[原创☆☆]
----- 一:我们先来了解下实际内存: nand.nor.ram. 所以从CPU是从那部分启动的呢? 答:要看主控芯片的boot如何设置(正如分的启动方式和下载方式一样). uboot:sd卡→iR ...
- INV Close Period & GL Import Journal > DML tables
1. (N) Inventory > Accounting Close Cycle > Inventory Accounting Periods Insert data ...
- 函数page_cur_search_with_match
/****************************************************************//** Searches the right position fo ...
- WPF——传实体类
User u; private void Button_Click_1(object sender, RoutedEventArgs e) //点击登陆按钮,弹出新窗体 { //先判断一下是不是正确的 ...
- jquery easyui datebox 的使用
看了jquery easyui databox的官方api,还可以加入倒是很简单,但是想要获得他的值和修改值就很费劲,不知道怎么弄,试了n次终于搞定.这里总结一下,供有相同问题的人查询. 1. 官方a ...