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. 【Python + ATX基于uiautomator2】之编写unittest自动化测试脚本

    不说废话上代码: #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/08/31 09:43 # @Author : zc # @ ...

  2. Linux Linux常用命令一

    ls-查看文件信息 -ls是英文单词list的简写,其功能为列出目录的内容,使用户最常用的命令之一 -它类似于DOS下的dir命令 ls[参数] 目录或文件 常用的参数及含义 "-a&quo ...

  3. 受限玻尔兹曼机(RBM, Restricted Boltzmann machines)和深度信念网络(DBN, Deep Belief Networks)

    受限玻尔兹曼机对于当今的非监督学习有一定的启发意义. 深度信念网络(DBN, Deep Belief Networks)于2006年由Geoffery Hinton提出.

  4. wpf数据绑定更新通知

    类似于这样子的;大致的意思是:一个代码变量,通过改变变量的值,绑定这个变量的这个圆颜色也在变化 就是一种心跳效果 在网上数据触发的感觉不多,废了不少时间,这里做个总结 1:通知 class Notif ...

  5. PHP基础面试题(1-10)

    1.什么是PHP? PHP是一个基于服务端来创建动态网站的脚本语言,可以通过PHP和HTML 生成网站主页. 2.什么是面向对象?主要特征是什么? 面向对象是程序的一种设计方式,利于提高程序的重用性, ...

  6. Machine Learning第十周笔记:大规模机器学习

    博客已经迁移到Marcovaldo's blog (http://marcovaldong.github.io/) 刚刚完毕了Andrew Ng在Cousera上的Machine Learning的第 ...

  7. activity通过流程实例id动态获取流程图并展示在jsp页面上

    提供的Service方法如下: Java /** * 获取当前任务流程图 * * @param processInstanceId * @return */ @Override public Inpu ...

  8. timus1965(不错的贪心)

    题意是:给你一个1-n的排列,要你把这个排列分成两个序列,且这个两个序列都满足单调性. 题解: 1.首先假设找出的两个序列都是单调递增的(都是单调递减的同理) 那么很容易可以想到,将新加入的数放入到某 ...

  9. 整理前端css/js/jq常见问题及解决方法(2)

    移动端 手机 1.点击图片或按钮,选中状态影响到其他范围解决:html{-webkit-user-select:none}<meta name="msapplication-tap-h ...

  10. Service 事务(JdbcUtils 升级)

    1. DAO 事务 // 在 DAO 中处理事务真是"小菜一碟" public void xxx(){ Connection con = null; try{ con = Jdbc ...