• 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 }
    这是我的第一篇博客,谢谢关注。

  • 相关阅读:
    MySql-数据库基础
    Window安装MySQL
    Python程序中的进程操作-进程间通信(multiprocess.Queue)
    线程
    上传电影代码
    并发编程基础
    基于socketserver实现并发的socket编程
    模拟ssh远程执行命令
    GIT的使用,Pycharm中使用GitHub
    主机如何访问运行在虚拟机中的Django项目
  • 原文地址:https://www.cnblogs.com/pengge666/p/11474107.html
Copyright © 2020-2023  润新知