zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 72 (Rated for Div. 2) A题

    Problem Description:

    You play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the character has exp 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
    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 str, int and exp (1≤str,int≤108, 0≤exp≤108) — the initial strength and intelligence of the character and the number of free points, respectively.

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

    input

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


    output

    3
    1
    2
    0

    题意:分配exp点经验给力量s和智力i,求有多少种分配情况使s比i高。

    思路:分类讨论,模拟实现

    以下是又臭又长的AC代码:

     1 #include<bits/stdc++.h>
     2 
     3 using namespace std;
     4 #define int long long
     5 
     6 signed main(){
     7     int _;
     8     cin>>_;
     9     while(_--){
    10         int a,b,c;
    11         scanf("%lld%lld%lld",&a,&b,&c);
    12         if(c==0){
    13             if(a>b){
    14                 printf("1
    ");
    15             }else{
    16                 printf("0
    ");
    17             }
    18             continue;
    19         }
    20         if(a+c<=b){
    21             printf("0
    ");continue;
    22         }
    23         if(b+c<a) {
    24             printf("%lld
    ",c+1);continue;
    25         }
    26         if(a>b){
    27             int sum=a+b+c;
    28             if(sum%2==0){
    29                 int ans=a+c-sum/2;
    30                 printf("%lld
    ",ans);
    31             } else{
    32                 int ans=a+c-sum/2;
    33                 printf("%lld
    ",ans);
    34             }
    35             continue;
    36         }
    37         if(a==b){
    38             if(c%2)
    39                 c++;
    40             printf("%lld
    ",c/2);
    41             continue; 
    42         }
    43         if(a<b){
    44             int temp=b-a;
    45             c-=temp;
    46             if(c%2)
    47                 c++;
    48             printf("%lld
    ",c/2);
    49             continue; 
    50         }
    51     }
    52     return 0;
    53 }
    这是我的第一篇博客,谢谢关注。

  • 相关阅读:
    2016级算法第四次上机-B ModricWang的序列问题
    2016级算法第四次上机-A.Bamboo 和人工zz
    2016级算法第三次上机-G.Winter is coming
    2016级算法第三次上机-F.ModricWang的导弹防御系统
    2016级算法第三次上机-E.ModricWang's Polygons
    2016级算法第三次上机-D.双十一的抉择
    2016级算法第三次上机-C.AlvinZH的奇幻猜想——三次方
    2016级算法第三次上机-B.Bamboo和巧克力工厂
    2016级算法第三次上机-A.Bamboo的小吃街
    Self-introduction 自我介绍
  • 原文地址:https://www.cnblogs.com/pengge666/p/11474107.html
Copyright © 2011-2022 走看看