Change language :

Alex is attending a Halloween party with his girlfriend Silvia. At the party, Silvia spots a giant chocolate bar. If the chocolate can be served as only 1 x 1 sized pieces and Alex can cut the chocolate bar exactly K times, what is the maximum number of chocolate pieces Alex can cut and give Silvia?

Input Format
The first line contains an integer T, the number of test cases. T lines follow.
Each line contains an integer K

Output Format
T lines. Each line contains an integer that denotes the maximum number of pieces that can be obtained for each test case.

Constraints
1<=T<=10
2<=K<=107

Note
Chocolate needed to be served in size of 1 x 1 size pieces.
Alex can't relocate any of the pieces, nor can he place any piece on top of other.


题解:坑在输入范围上了,答案要用long型。

代码:

 import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*; public class Solution {
static long Halloween_party(long k){
if(k %2 ==0)
return (k/2)*(k/2);
return (k/2)*(k/2+1);
} public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0;i < t;i++){
long k = in.nextInt();
System.out.println(Halloween_party(k));
} }
}

【HackerRank】Halloween party的更多相关文章

  1. 【HackerRank】How Many Substrings?

    https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...

  2. 【HackerRank】Running Time of Quicksort

    题目链接:Running Time of Quicksort Challenge In practice, how much faster is Quicksort (in-place) than I ...

  3. 【hackerrank】Week of Code 30

    Candy Replenishing Robot Find the Minimum Number 直接模拟 Melodious password dfs输出方案 Poles 题意:有多个仓库,只能从后 ...

  4. 【hackerrank】Week of Code 26

    在jxzz上发现的一个做题网站,每周都有训练题,题目质量……前三题比较水,后面好神啊,而且类型差不多,这周似乎是计数专题…… Army Game 然后给出n*m,问需要多少个小红点能全部占领 解法:乘 ...

  5. 【HackerRank】Median

    题目链接:Median 做了整整一天T_T 尝试了各种方法: 首先看了解答,可以用multiset,但是发现java不支持: 然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大 ...

  6. 【HackerRank】Coin on the Table

    题目链接:Coin on the Table 一开始想用DFS做的,做了好久都超时. 看了题解才明白要用动态规划. 设置一个三维数组dp,其中dp[i][j][k]表示在时间k到达(i,j)所需要做的 ...

  7. 【HackerRank】Pairs

    题目链接:Pairs 完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数.总结其实就是“骑驴找马”的问题:即当前遍历ar[ ...

  8. 【HackerRank】Cut the tree

    题目链接:Cut the tree 题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小. 暴力求解会超时. 如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a ...

  9. 【HackerRank】Missing Numbers

    Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very pr ...

随机推荐

  1. Unity3D 移动开发代码优化

    1. 尽量避免每帧处理 比方: function Update() { DoSomeThing(); } 可改为每5帧处理一次: function Update() { if(Time.frameCo ...

  2. python第四周迭代器生成器序列化面向过程递归

      第一节装饰器复习和知识储备------------ 第一节装饰器复习和知识储备------------ def wrapper(*args,**kwargs): index(*args,**kwa ...

  3. vmware workstation 9.0.2安装教程

    现在为您分享最新的VMware Workstation 9.0正式版(VMware Workstation 9.0.0 Build 812388)的下载,同时附上注册机或者注册激活码. 下载地址:   ...

  4. Appium python自动化测试系列之元素的定位(六)

    ​6.1 常用定位方法讲解 对象定位是自动化测试中很关键的一步,也可以说是最关键的一步,毕竟你对象都没定位那么你想操作也不行.所以本章节的知识我希望大家多动手去操作,不要仅仅只是书本上的知识,毕竟这个 ...

  5. 【转】锤子CTO钱晨:福利好是一种堕落的公司文化

    “这是拉勾网对锤子科技CTO钱晨的访谈,作为中国手机界三大产品经理之一,他带领着一众硬件工程师在手机红海中厮杀.钱晨喜欢焦虑的工程师,佩服有方向感的人. 本文作者:西岳 拉勾网原创出品,转载请注明作者 ...

  6. hdu 1956(混合图的欧拉回路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1956 思路:先将无向边定向,比如1<->3,可以定它的方向为1->3,1的出度++, ...

  7. hdu 1815(二分+2-sat)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1815 题意:给出n个牛棚.两个特殊点S1,S2的坐标.S1.S2直连.牛棚只能连S1或S2,还有,某些 ...

  8. iOS面试题--Model层--沙盒的目录结构是怎么样的?各自一般用于什么场合?

    沙盒的目录结构是怎么样的?各自一般用于什么场合? 一.iOS沙盒机制 iOS的应用只能访问为该应用创建的区域,不可访问其他区域,应用的其他非代码文件都存在此目录下,包括图片,属性文件plist,bun ...

  9. iOS面试题--Model层--数据持久化储存方案

    数据持久化储存方案有哪些? iOS中的数据持久化方式,基本上有以下四种:属性列表.对象归档.SQLite3和Core Data 1.属性列表涉及到的主要类:NSUserDefaults,一般 [NSU ...

  10. sublime text3 安装配置

    sublime text 3 语法检查插件(一直都是安装了但是却没有语法报错提示和苦恼) 第一种方法:有点卡 先去下载对应的开发环境,安装到本地,例如php. 从Pakage Control中安装su ...