博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Chessboard(规律)&&阿里巴巴和n个大盗(规律)
阅读量:4329 次
发布时间:2019-06-06

本文共 2629 字,大约阅读时间需要 8 分钟。

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 (
T10000).  In the next T lines contain T cases , Each case has two integers n and k. (1n,k100)
 

 

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
#include
#include
#include
#include
#include
#include
#include
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("0");continue; } printf("%d\n",n*n-min(n%k,k-n%k)*min(n%k,k-n%k)); } return 0;}

 

阿里巴巴和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个宝石(1n2m21≤n≤2⋅m−2, 2m1002≤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
#include
#include
#include
#include
using namespace std;const int INF=0x3f3f3f3f;int main(){ int n,m; while(~scanf("%d%d",&n,&m)){ n++; if(n==2)puts("-1"); else if(n==3)printf("%d\n",m); else printf("%d\n",m-(n+1)/2); } return 0;}

 

 

转载于:https://www.cnblogs.com/handsomecui/p/5257856.html

你可能感兴趣的文章
2016 - 1 -17 GCD学习总结
查看>>
linux安装php-redis扩展(转)
查看>>
Vue集成微信开发趟坑:公众号以及JSSDK相关
查看>>
技术分析淘宝的超卖宝贝
查看>>
i++和++1
查看>>
react.js
查看>>
P1313 计算系数
查看>>
NSString的长度比较方法(一)
查看>>
Azure云服务托管恶意软件
查看>>
My安卓知识6--关于把项目从androidstudio工程转成eclipse工程并导成jar包
查看>>
旧的起点(开园说明)
查看>>
生产订单“生产线别”带入生产入库单
查看>>
crontab导致磁盘空间满问题的解决
查看>>
java基础 第十一章(多态、抽象类、接口、包装类、String)
查看>>
Hadoop 服务器配置的副本数量 管不了客户端
查看>>
欧建新之死
查看>>
自定义滚动条
查看>>
APP开发手记01(app与web的困惑)
查看>>
笛卡尔遗传规划Cartesian Genetic Programming (CGP)简单理解(1)
查看>>
mysql 日期时间运算函数(转)
查看>>