文章目录

  • 一、Candies and Two Sisters
  • 总结

一、Candies and Two Sisters

本题链接:Candies and Two Sisters

题目
A. Candies and Two Sisters
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that:

Alice will get a (a>0) candies;
Betty will get b (b>0) candies;
each sister will get some integer number of candies;
Alice will get a greater amount of candies than Betty (i.e. a>b);
all the candies will be given to one of two sisters (i.e. a+b=n).
Your task is to calculate the number of ways to distribute exactly n candies between sisters in a way described above. Candies are indistinguishable.

Formally, find the number of ways to represent n as the sum of n=a+b, where a and b are positive integers and a>b.

You have to answer t independent test cases.

Input
The first line of the input contains one integer t (1≤t≤104) — the number of test cases. Then t test cases follow.

The only line of a test case contains one integer n (1≤n≤2⋅109) — the number of candies you have.

Output
For each test case, print the answer — the number of ways to distribute exactly n candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print 0.

Example
input
6
7
1
2
3
2000000000
763243547
output
3
0
0
1
999999999
381621773

Note
For the test case of the example, the 3 possible ways to distribute candies are:

a=6, b=1;
a=5, b=2;
a=4, b=3.

本博客给出本题截图

题意:一共n个糖,给两个姐妹分糖吃,要求Alice得到的糖要比Betty多,问有几种分法

AC代码

#include <iostream>using namespace std;int main()
{int n;cin >> n;while (n -- ){int a;cin >> a;if (a % 2) cout << a / 2 << endl;else cout << (a - 1) / 2 << endl;}return 0;
}

总结

观察输入输出猜规律

Candies and Two Sisters相关推荐

  1. Codeforces Round #634 (Div. 3)A. Candies and Two Sisters

    题目: A. Candies and Two Sisters time limit per test : 1 second memory limit per test : 256 megabytes ...

  2. Codeforces Round #634 (Div. 3)ABCD

    传送门 这场div3全都是模拟暴力题,第一次打到E1题,E2我tle了后面再补把,a.a 看见t神22分钟ak 文章目录 A.Candies and Two Sisters B.Construct t ...

  3. K - Candies POJ - 3159(利用了自定义比较操作符)

    K - Candies POJ - 3159 题意: 孩子 A 觉得 B 得到的糖果不能比自己多超过 c,求 n 比 1 最多能多几颗糖果 思路:DJ,松弛条件: sweet[A] > swee ...

  4. AtCoder Beginner Contest 215 G - Colorful Candies 2

    AtCoder Beginner Contest 215 G - Colorful Candies 2 有n个糖果,每个糖果有着一个颜色a[i],每次拿k个糖果期望拿到E(x)个不同颜色的糖果,求出k ...

  5. 575. Distribute Candies 平均分糖果,但要求种类最多

    [抄题]: Given an integer array with even length, where different numbers in this array represent diffe ...

  6. 1431. Kids With the Greatest Number of Candies

    Title 给你一个数组 candies 和一个整数 extraCandies ,其中 candies[i] 代表第 i 个孩子拥有的糖果数目. 对每一个孩子,检查是否存在一种方案,将额外的 extr ...

  7. HDU - 6126 Give out candies

    Give out candies 题解: 第一次遇见这样处理的网络流模型. 将问题转换成最小割问题. 具体的题解参考自:传送门 先将每个人的拆成m个人. 然后s向第1人连边流量为inf.第i个人向第i ...

  8. CF思维联系– CodeForces - 991C Candies(二分)

    ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...

  9. poj 2886 Who Gets the Most Candies?(线段树)

    题目链接:poj 2886 Who Gets the Most Candies? 题目大意:N个人围成一圈玩约瑟夫环游戏,不同的是.步长不固定,由前一个出局的人决定.给定K表示起始的人. 第i个淘汰的 ...

最新文章

  1. 使用fluentd管理docker日志
  2. [云炬创业学笔记]第二章决定成为创业者测试8
  3. [公告]博客园恢复正常运行
  4. android震动提示音,android的消息提示(震动与提示音)
  5. java登录界面命令_Java命令行界面(第5部分):JewelCli
  6. java中Date类、DateFormat及SimpleDateFormat简介
  7. c语言中字符串数组应用,C语言中字符变量字符串和字符数组应用.doc
  8. 华为Mate X海报曝光:设计惊艳 可变形
  9. Windows 7安装到虚拟磁盘VHD文件中
  10. linux中程序定时重启脚本,linux下通过脚本实现自动重启程序的方法
  11. 三元运算符最终结果的数据类型
  12. python通过多进程实行多任务
  13. C++ malloc new 的区别
  14. win10 实现远程连接linux系统
  15. 激光SLAM导航系列(一)SLAM与导航基本原理
  16. python---导入 py文件
  17. python cvxpy 报错 The solver GLPK_MI is not installed
  18. Python发送邮件(demo)
  19. NPOI创建DOCX常用操作
  20. 一位AI大佬给算法校招同学的建议:观点篇

热门文章

  1. python爬虫 - 起点女生榜单爬取 - 1
  2. 和声是容介态——为《链政经济:区块链如何服务新时代治国理政》一书作序
  3. 【WP 8.1开发】解决调用真实摄像头会死机的问题
  4. 微信小程序卖货收费吗?企业公司商家要知道的
  5. 【欧式距离:二维和三维定位算法】
  6. 【转】功能测试报告的编写
  7. 手机修改服务器流量,云服务器变手机流量
  8. 【软件分享】阅读APP:免费开源无广告、全网小说免费看(附2613个书源)
  9. upload-labs-04
  10. 9月第2周业务风控关注 | 《网络生态治理规定(征求意见稿)》公开征求意见