1. 程式人生 > >華東交通大學2017年ACM“雙基”程序設計競賽 1003

華東交通大學2017年ACM“雙基”程序設計競賽 1003

size 小球 problem cout output () add 兩個 ace

Problem Description

有兩個球在長度為L的直線跑道上運動,兩端為墻。0時刻小球a以1m/s的速度從起點向終點運動,t時刻小球b以相同的速度從終點向起點運動。問T時刻兩球的距離。這裏小球與小球、小球與墻的碰撞均為彈性碰撞,所有過程沒有能量損失。

Input

先輸入一個q,代表q組數據,然後每組3個整數 L,t,T。
1<=L<=1000;0<=t<=1000;t<=T<=1000;

Output

一個整數,代表答案。

Sample Input

2
10 4 7
8 3 9

Sample Output

0
5

解法:模擬~
 1 #include<bits/stdc++.h>
 2
#define clr(x) memset(x,0,sizeof(x)) 3 #define LL long long 4 using namespace std; 5 #define INF 0x3f3f3f3f 6 typedef long long ll; 7 const int N= 30 +9; 8 struct Matrix 9 { 10 int m[N][N]; 11 }; 12 int Dinit,Dend; 13 int add,sub; 14 int main() 15 { 16 int test; 17 int
L,t,T; 18 cin>>test; 19 while(test--) 20 { 21 cin>>L>>t>>T; 22 Dinit=0,Dend=L; 23 add=1,sub=-1; 24 for(int i=1;i<=T;i++) 25 { 26 if(i>t){Dinit+=add,Dend+=sub;} 27 else{Dinit+=add;} 28 if
(Dinit==Dend){add=-1,sub=1;} 29 if(Dinit==0){add=1;} 30 if(Dinit==L){add=-1;} 31 if(Dend==0){sub=1;} 32 if(Dend==L){sub=-1;} 33 } 34 cout<<abs(Dend-Dinit)<<endl; 35 } 36 return 0; 37 }


華東交通大學2017年ACM“雙基”程序設計競賽 1003