"C + +" ccfcsp201803-2 colliding ball

Source: Internet
Author: User

Tag:name   include    number    using   ccf    class    Sport     Cycle     scale    

main.cpp//ccfcsp20180318_2_ Collision Ball////Created by t.p on 2018/3/24.//Copyright? 2018 T.P. All rights reserved.///* Collision Ball 1.0s 256.0MB Problem description There is a line with a length of L (l is even), the left end is at the origin, and the right end point is at the coordinates L.   There are n non-volume balls on the line segment, and at the beginning all the balls are in even coordinates, the velocity direction to the right, and the speed of 1 units per second.   When the ball reaches the end point of the line segment (the left or right end), it moves in the opposite direction immediately, and the velocity is still the same size.   When two small balls collide with each other, the two balls will move in the opposite direction to the original moving direction, moving with the original speed. Now, tell you the length of the line segment L, the number of balls N, and the initial position of the N ball, please calculate the position of each ball after t seconds.   Tip because the initial position of all the balls is even, and the length of the line is even, it can be proved that no three balls collide at the same time, the ball reaches the end of the segment and the collision between the balls is an integer. It is also possible to prove that the location of the two ball collisions must be an integer (but not necessarily an even number).   Input format the first line of input contains three integers n, L, T, separated by a space, representing the number of balls, the length of the segment, and the position of the ball you need to calculate after t seconds. The second line contains n integers a1, A2,?, an, separated by a space, representing the position of the initial moment n balls. The output format output line contains n integers, separated by spaces, and the first integer represents the initial moment of the AI's ball, where it is after t seconds. Sample Input 3 10 5 4 6 8 Sample output 7 9 9 Sample input 10 22 30 14 12 16 6 10 2 8 20 18 4 Sample Output 6 6 8 2 4 0 4 12 10 2 data size and conventions for all evaluation cases, 1≤n ≤100,1≤t≤100,2≤l≤1000,0 < AI < L.   L is an even number. Ensure that the initial positions of all spheres are different and are even. */#include <iostream>using namespace Std;int main () {int n=0;//ball number int l=0;//segment length int t=0;//time int q[10 0]={0};//StorageBall initial position int q2[100]={0};//staging last second small ball position int qf[100]={0};//Deposit Ball Current motion direction, 1 right, 1 left for (int i=0;i<100;i++)//ball motion direction initialized to right    Qf[i]=1;    cin>>n>>l>>t;              for (int i=0;i<n;i++) cin>>q[i];    At this point the implementation of the input requirements of the M1 int;    int m2;        for (int i=0;i<t;i++) {//outermost implementation of the cycle of the T-cycle for (int i=0;i<n;i++)//Temporarily save the last periodic ball motion direction q2[i]=q[i]; for (m1=0;m1<n;m1++) {if (q2[m1]==l&&qf[m1]==1) | | (Q2[m1]==0&&qf[m1]==-1))            two endpoints qf[m1]=-qf[m1];                        Collision between else//balls for (m2=0;m2<n;m2++) if (q2[m1]==q2[m2]&&m1!=m2)            QF[M1]=-QF[M1];        Q[M1]=Q[M1]+QF[M1];    }} for (int i=0;i<n;i++) cout<<q[i]<< "";    cout<<endl; return 0;}

C + + ccfcsp201803-2 colliding balls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.