Chessboard

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 919    Accepted Submission(s): 390

Problem Description
Consider the problem of tiling an n×n chessboard by polyomino pieces that are k×1 in size; Every one of the k pieces of each polyomino tile must align exactly with one of the chessboard squares. Your task is to figure out the maximum number of chessboard squares tiled.
 
Input
There are multiple test cases in the input file. First line contain the number of cases T (T≤10000).  In the next T lines contain T cases , Each case has two integers n and k. (1≤n,k≤100)
 
Output
Print the maximum number of chessboard squares tiled.
 
Sample Input
2
6 3
5 3
 
Sample Output
36
24
 

题解:由上图可以看出,可以针对n%k的余数排列,所以只需要判断n%k和k-n%k的大小,n*n-这个值就好了;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
#define mem(x,y) memset(x,y,sizeof(x))
typedef __int64 LL;
int main(){
int T,n,k;
SI(T);
while(T--){
scanf("%d%d",&n,&k);
if(k>n){
puts("");continue;
}
printf("%d\n",n*n-min(n%k,k-n%k)*min(n%k,k-n%k));
}
return ;
}

阿里巴巴和n个大盗

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status

阿里巴巴和nn个大盗来到了一个藏满宝石的洞穴。洞里一共有mm颗价值连城的宝石,每一颗都等价。盗亦有道,为了奖励帮忙打开洞穴门的阿里巴巴,大盗们决定让他一起加入分赃。大盗们决定采用一种方式分赃,分赃的方式如下:

1)每个人由抽签决定了自己的号码(11, 22, 33, ⋯⋯, n+1n+1)。

2)由n+1n+1号提出分配方案,然后大家表决,当且仅当超过半数的人同意时(包括他自己),按照他的方案进行分配,否则这个人将被杀死。

3)n+1n+1号死后,由nn号接替n+1n+1号对剩下的人提出分配方案,类似22步骤。以此类推。

大盗们都有如下的几个性格特点

1)足智多谋,总是采取最优策略。

2)贪生怕死,尽量保全自己性命。

3)贪得无厌,希望自己得到越多宝石越好

4)心狠手辣,在自己利益最大的情况想希望越多人死越好。

5)疑心多虑,不信任彼此,尽量确保自身利益不寄希望与别人给自己更大利益。

不知道是不幸还是幸运,阿里巴巴抽到了n+1n+1号签,意味着他将第一个提出分配方案。他想请教机智的你,他能否活下来,如果能又将获得最多多少个宝石?

Input

两个整数nn, mm,分别表示nn个大盗和mm个宝石(1≤n≤2⋅m−21≤n≤2⋅m−2, 2≤m≤1002≤m≤100)。

Output

如果阿里巴巴能活下来输出一个整数xx表示阿里巴巴最多获得的宝石数,否则输出−1−1。

Sample input and output

Sample Input Sample Output
4 100
97

Hint

分配方案 0 2 1 0 97 或2 0 1 0 97(从11号到55号)。

题解:

很神奇的题,很难找出来这个规律额,脑懂还是不行;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
n++;
if(n==)puts("-1");
else if(n==)printf("%d\n",m);
else printf("%d\n",m-(n+)/);
}
return ;
}

Chessboard(规律)&&阿里巴巴和n个大盗(规律)的更多相关文章

  1. cdoj 1253 阿里巴巴和n个大盗 博弈论

    阿里巴巴和n个大盗 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1253 D ...

  2. Visible Lattice Points(规律题)【数学规律】

    Visible Lattice Points 题目链接(点击) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9031   ...

  3. POJ2505 A multiplication game 博弈论 找规律

    http://poj.org/problem?id=2505 感觉博弈论只有找规律的印象已经在我心中埋下了种子... 题目大意:两个人轮流玩游戏,Stan先手,数字 p从1开始,Stan乘以一个2-9 ...

  4. BNU29140——Taiko taiko——————【概率题、规律题】

    Taiko taiko Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class ...

  5. 【NOIP 模拟赛】中值滤波 打表找规律

    对于这样看起来不像什么算法也没什么知识点的题,一脸懵逼的话不是手推规律就是打表找规律......... 当然还有一些超出你能力之外的数学题...... #include <cstdio> ...

  6. 递推:Number Sequence(mod找规律)

    解题心得: 1.对于数据很大,很可怕,不可能用常规手段算出最后的值在进行mod的时候,可以思考找规律. 2.找规律时不必用手算(我傻,用手算了好久).直接先找前100项进行mod打一个表出来,直接看就 ...

  7. [LeetCode] Transform to Chessboard 转为棋盘

    An N x N board contains only 0s and 1s. In each move, you can swap any 2 rows with each other, or an ...

  8. UESTC--1253--阿里巴巴和n个大盗 (博弈)

     阿里巴巴和n个大盗 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Submit St ...

  9. Linux 江湖系列阶段性总结

    引言 我使用 Linux 已经有很多年了,最开始接触 Linux 的时候是从 RedHat 9(没有 Enterprise),中途换过 N 个不同的发行版.多年前,我在 BlogJava 上面分享 J ...

随机推荐

  1. c++容器使用总结(转载)

    目录 ==================================================== 第一章 容器 第二章 Vector和string 第三章 关联容器 第四章 迭代器 第五 ...

  2. 456. 132 Pattern

    456. 132 Pattern Given an array of integers a1, a2, a3-an, judge if there exists the 132 pattern. 13 ...

  3. 很少人知道的office专用卸载工具

    Microsoft Office是微软公司开发的一套基于 Windows 操作系统的办公软件套装.常用组件有 Word.Excel.Powerpoint等.当我们不需要再用了或者想安装旧版本的话,首先 ...

  4. Struts2(一)——总体介绍

    这篇博客开始将总结一下有关框架的知识,在开发中合适的利用框架会使我们的开发效率大大提高.当今比较流行的开源框架: 关注数据流程的MVC框架 (Struts1/2, WebWork, Spring MV ...

  5. ibatis错误汇总

    1) 错误:The prefix "context" for element "context:property-placeholder" is not bou ...

  6. locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory

    安装好CentOS后,第一次进入系统使用locate命令,结果出现:locate: can not stat () `/var/lib/mlocate/mlocate.db': No such fil ...

  7. HDU 1068 - Girls and Boys

    求一个集合最多几个人,其之间任意两人没有暧昧关系. 二分图匹配 最大独立集 = 总点数 - 最大匹配数 匈牙利算法 因为每个同学都在二分图的两侧 当 A与B匹配时,B与A也匹配 所以 所求的最大匹配数 ...

  8. stl的集合set——安迪的第一个字典(摘)

    set就是数学上的集合——每个元素最多只出现一次,和sort一样,自定义类型也可以构造set,但同样必须定义“小于”运算符 以下代码测试set中无重复元素 #include<iostream&g ...

  9. 测试工具:insure++

    CSDN资源:http://www.csdn.net/tag/insure%252B%252B 安装. 1,简介:http://baike.baidu.com/link?url=bCcoWd3xi07 ...

  10. CDZSC_2015寒假新人(1)——基础 e

    Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever ...