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

  • 相关阅读:
    [No000088]并行循环vs普通循环
    [No000087]Linq排序,SortedList排序,二分法排序性能比较
    [No000086]C#foreach集合被改变,报错处理方案
    [No000085]C#反射Demo,通过类名(String)创建类实例,通过方法名(String)调用方法
    [No000084]C# 使用Log4Net(1)-快速建立一个demo
    [No000082]Convert和Parse的区别/Convert.ToInt32()与int.Parse()的区别
    [No000081]SVN学习笔记1-服务端搭建
    [No00007F]2016-面经[下] 英文简历写作技巧
    [No00007E]2016-面经[中]
    [No00007D]2016-面经[上]
  • 原文地址:https://www.cnblogs.com/pengge666/p/11474107.html
Copyright © 2011-2022 走看看