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). p>
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
< span style="color: #800080;">3
1
2
0
Question meaning: Assign Exp point experience is given to strength s and intelligence i, find how many distribution situations make s higher than i.
Thinking: categorized discussion, simulation implementation.
The following is the smelly and long AC code:
1 # include
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< span style="color: #000000;">;
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 }
This is my first Thank you for your attention.
4
5 3 4
2 1 0
3 5 5
4 10 6
3
1
2
0
1 span> #include22 }
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< span style="color: #000000;">;
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 }