# 【Codeforces】1217A - Creating a Character

### Problem Description：

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 1 or raise intelligence by 1).

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 Specification:

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

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

### Output Specification:

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

```4
5 3 4
2 1 0
3 5 5
4 10 6```

```3
1
2
0```

### Note:

In the first query there are only three appropriate character builds: (str=7,int=5), (8,4) and (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).

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

In the fourth query all builds have too much brains.

### 解题思路：

+e<=i就会出现负数，此时怎么点经验都是徒劳，所以要拿e-i+s和0进行比较取最大值；③当s>=i时 俩者相差s-i，则(s-i+e)除以2再向上取整。最后取三种情况的最大值即可。

### AC代码：TLE代码：

```#include <bits/stdc++.h>
using namespace std;
#define Up(i,a,b) for(int i = a; i <= b; i++)

int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
int s,i,exp,cnt = 0;
cin >> s >> i >> exp;
Up(j,0,exp)
{
int _s = s+j;
int _i = i+exp-j;
if(_s > _i)
{
cnt++;
}
}
cout << cnt << endl;
}
return 0;
}```

### AC代码：

```#include <bits/stdc++.h>
using namespace std;

int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
int s,i,e,cnt = 0;
cin >> s >> i >> e;
int _ = ceil((e-i+s)/2.0);
cout << min(e+1, max(_,0)) << endl;   //当s>i+e时就是e+1
}
return 0;
}```

0 条评论

• ### 【Codeforces】1213B - Bad Prices

版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明。 ...

• ### 【PAT甲级】The Black Hole of Numbers

版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明。 ...

• ### 【PAT甲级】The Missing Number

版权声明：本文为博主原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接和本声明。 ...

• ### HDUOJ----2489 Minimal Ratio Tree

Minimal Ratio Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768...

• ### Leetcode 174 Dungeon Game

The demons had captured the princess (P) and imprisoned her in the bottom-right...

• ### P2880 [USACO07JAN]平衡的阵容Balanced Lineup

题目背景 题目描述： 每天,农夫 John 的N(1 <= N <= 50,000)头牛总是按同一序列排队. 有一天, John 决定让一些牛们玩一场飞盘比赛....

• ### imp错误IMP-00098: INTERNAL ERROR: impgst2Segmentation fault

如果使用impdp要看dump的内容，可以使用sqlfile参数，他会将所有的DDL语句写入文件，

• ### 独角兽与数列（置换群循环）- HDU 4985

群论是法国数学家伽罗瓦（Galois）的发明。伽罗瓦是一个极具传奇性的人物，年仅21岁就英年早逝于一场近乎自杀的决斗中。他用该理论，具体来说是伽罗瓦群，解决了五...

• ### 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D

• ### 环境反向散射通信中断性能研究（CS）

环境反向散射通信（AmBackComs）被认为是物联网的一种频谱和节能技术，因为它允许被动反向散射设备（BDs）将其信息调制成传统信号，例如蜂窝信号，并将它们反...