<span>[Educational Codeforces Round 72] A. Creating a Character (简单数学)</span>

[Educational Codeforces Round 72] A. Creating a Character (简单数学)

A. Creating a Character

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy

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

output

Copy

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.

题意:

你被给与三个整数\(x,y,z\),你可以把\(\mathit z\) 拆分为\(z=a+b\) ,然后让\(a,b\)分别赋值给\(x,y\),即使\(x=x+a,y=y+b\)

现在问你有多少个种方式,使最后的\(x>y\)

思路:

先将\(\mathit z\) 全加到\(\mathit x\) 上,得\(x=x+z\),我们只需要从\(\mathit x\)中减去一个数,将其加给\(\mathit y\) ,且使\(x>y\)

等于求满足该不等式的a的数量,\(x-a>y+a\),化简:\(x-y>2*a\),由不等式性质我们知道:

\(\mathit a\)的取值数量为\(\lceil\frac{x-y}{2}\rceil\),又因为\(\mathit a\)有意义的取值范围是:\([0,z]\),所以答案为:

\(ans=min(max(\lceil\frac{x-y+z}{2}\rceil,0),z+1)\)

Ps:这题答案的上限和下限没思考清楚的很容易wa。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/

int main()
{
    //freopen("D:\\code\\text\\input.txt","r",stdin);
    //freopen("D:\\code\\text\\output.txt","w",stdout);
    int t;
    t = readint();
    while (t--)
    {
        ll x, y, z;
        x = readll();
        y = readll();
        z = readll();
        x = x + z - y;
        ll ans = 0ll;
        if (x > 0) {
            ans = x >> 1;
            if (x & 1)
            {
                ans++;
            }
        }
        ans = min(ans, z + 1ll);
        printf("%lld\n", ans );
    }

    return 0;
}



全部评论

相关推荐

我是985研究生,最近学校在组织开题,大家都在非常紧张地准备,但我一直进入不了状态,很想做但是心又很浮躁。但我的室友们感觉都非常认真,每天醒来就开始看论文,睡着前最后一件事还是在看论文,我非常焦虑。我感觉自己甚至有点把大家当做假想敌了。这种比较心态还存在于生活的各种方面:看到有钱的同学会非常羡慕,看到朋友圈里面环游世界的留学生同学也会羡慕,看到那些工作后有自己的钱而过上较为阔绰的生活的时候还是羡慕,就仿佛只有自己一个人在阴暗爬行。而且这些比较是每时每刻的,为了不比较,我已经关闭了朋友圈,但是每次偶尔刷一下还是会难受很久。我知道比较是偷走幸福的小偷,但我好像控制不了,感觉自己是一个偷窥别人生活的...
若怜君欢:担心开题搞砸了,幻想拥有别人的生活,本质上是因为自卑,楼主小时候大概率是留守儿童或者父母关系很紧张,导致楼主没有安全感、焦虑、内耗。 这样的情况最好的办法就是建立自信和降低期待,建立自信不是一蹴而就,而是循序渐进,比如告诉自己允许自己第一次没把事情做好,失败了能搞清楚其中缘由而不是全盘否定自己,失败不是终点,放弃才是;降低期待只要记住一句话即可,能伴随你一生的,只有经验和学识,所以你对事情的态度应该更多地去思考它是否能带来学识和经验的增长,而不是仅仅用短期的利益作为唯一期待。 人生不是一成不变的,它是可以迭代更新的,去归纳总结自身的不足并结合实际去改进,去尝试一些新的思路和方法,不要固执钻牛角尖,也不要反复横跳,为自己设立一个高度聚集的精神内核,内核之上可以去尝试一切有利于自己更好的方式 以上就是我个人对生活的理解,共勉
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务