【Codeforces】1217A. Creating a Character

题目描述

You play your favourite game yet another time. You chose the character you didn’t play before. It has strstr points of strength and intint points of intelligence. Also, at start, the character has expexp free experience points you can invest either in strength or in intelligence (by investing one point you can either raise strength by 11 or raise intelligence by 11).

Since you’d like to make some fun you want to create a jock character, so it has more strength than intelligence points (resulting strength is strictly greater than the resulting intelligence).

Calculate the number of different character builds you can create (for the purpose of replayability) if you must invest all free points. Two character builds are different if their strength and/or intellect are different.

Input

The first line contains the single integer TT (1≤T≤1001≤T≤100) — the number of queries. Next TT lines contain descriptions of queries — one per line.

This line contains three integers strstr, intint and expexp (1≤str,int≤1081≤str,int≤108, 0≤exp≤1080≤exp≤108) — the initial strength and intelligence of the character and the number of free points, respectively.

Output

Print TT integers — one per query. For each query print the number of different character builds you can create.

Example

input
4
5 3 4
2 1 0
3 5 5
4 10 6
output
3
1
2
0

Note

In the first query there are only three appropriate character builds: (str=7,int=5)(str=7,int=5), (8,4)(8,4) and (9,3)(9,3). All other builds are either too smart or don’t use all free points.

In the second query there is only one possible build: (2,1)(2,1).

In the third query there are two appropriate builds: (7,6)(7,6), (8,5)(8,5).

In the fourth query all builds have too much brains.

题解

题意

创造一个角色,这个角色有Strength和Intelligence两个属性,你可以随意的进行分配exprience到两个属性上。在每一个给定的输入中,有三个数strength, intelligence, exprience,前两个数表示选择的角色固有的属性,后一个数是待分配的属性点,要求该创造的角色Strength属性严格大于Intelligence属性,求可以创造出多少种角色。

思路

假设分给strength的点数是x,则st+x>in+ex-x,即x>(in+ex-st)/2。

需要注意的是:

当ex==0时,直接判断st与in的关系,若st>in则输出1,否则输出0;

若in+ex-st<0,则给strength分配的值从0开始。

代码

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int st,in,ex;

int main()
{
    int t;
    cin>>t;
    while(t--){
        cin>>st>>in>>ex;
        if (ex==0){
            if(st>in)
				cout<<1<<endl;
            else
				cout<<0<<endl;
        }
        else{
        	int Min=in+ex-st;
		    if(Min<0){
		        Min=0;
		    }
		    else{
		        Min=Min/2+1;
		    }
		    int ans=max(ex-Min+1,0);
		    cout<<ans<<endl;
		}
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值