Candies and Two Sisters
文章目录
- 一、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相关推荐
- 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 ...
- Codeforces Round #634 (Div. 3)ABCD
传送门 这场div3全都是模拟暴力题,第一次打到E1题,E2我tle了后面再补把,a.a 看见t神22分钟ak 文章目录 A.Candies and Two Sisters B.Construct t ...
- K - Candies POJ - 3159(利用了自定义比较操作符)
K - Candies POJ - 3159 题意: 孩子 A 觉得 B 得到的糖果不能比自己多超过 c,求 n 比 1 最多能多几颗糖果 思路:DJ,松弛条件: sweet[A] > swee ...
- AtCoder Beginner Contest 215 G - Colorful Candies 2
AtCoder Beginner Contest 215 G - Colorful Candies 2 有n个糖果,每个糖果有着一个颜色a[i],每次拿k个糖果期望拿到E(x)个不同颜色的糖果,求出k ...
- 575. Distribute Candies 平均分糖果,但要求种类最多
[抄题]: Given an integer array with even length, where different numbers in this array represent diffe ...
- 1431. Kids With the Greatest Number of Candies
Title 给你一个数组 candies 和一个整数 extraCandies ,其中 candies[i] 代表第 i 个孩子拥有的糖果数目. 对每一个孩子,检查是否存在一种方案,将额外的 extr ...
- HDU - 6126 Give out candies
Give out candies 题解: 第一次遇见这样处理的网络流模型. 将问题转换成最小割问题. 具体的题解参考自:传送门 先将每个人的拆成m个人. 然后s向第1人连边流量为inf.第i个人向第i ...
- CF思维联系– CodeForces - 991C Candies(二分)
ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...
- poj 2886 Who Gets the Most Candies?(线段树)
题目链接:poj 2886 Who Gets the Most Candies? 题目大意:N个人围成一圈玩约瑟夫环游戏,不同的是.步长不固定,由前一个出局的人决定.给定K表示起始的人. 第i个淘汰的 ...
最新文章
- 使用fluentd管理docker日志
- [云炬创业学笔记]第二章决定成为创业者测试8
- [公告]博客园恢复正常运行
- android震动提示音,android的消息提示(震动与提示音)
- java登录界面命令_Java命令行界面(第5部分):JewelCli
- java中Date类、DateFormat及SimpleDateFormat简介
- c语言中字符串数组应用,C语言中字符变量字符串和字符数组应用.doc
- 华为Mate X海报曝光:设计惊艳 可变形
- Windows 7安装到虚拟磁盘VHD文件中
- linux中程序定时重启脚本,linux下通过脚本实现自动重启程序的方法
- 三元运算符最终结果的数据类型
- python通过多进程实行多任务
- C++ malloc new 的区别
- win10 实现远程连接linux系统
- 激光SLAM导航系列(一)SLAM与导航基本原理
- python---导入 py文件
- python cvxpy 报错 The solver GLPK_MI is not installed
- Python发送邮件(demo)
- NPOI创建DOCX常用操作
- 一位AI大佬给算法校招同学的建议:观点篇