Description
This game is usually used between Mr. s and Mr. L to decide who treats us ......
There are n coins in a row on the desktop, and they start with a front-up (expressed as 1). Now K operations are performed, each operation is to flip the continuous coin from number A to number B, that is, the front is now the opposite, the original back, now the front.
Their decision is: after these K operations, count the number of front and back to decide who to treat ......
Your job is to count the number of front and back coins.
-
Input
-
The first line of the input contains an integer T, indicating that T groups of data exist.
The first row of each group of data contains two integers, n (<= 1000) and K (<= 500), indicating that there are n coins and K operations.
In the next K rows, each line contains two integers A and B, indicating the number start point and end point of the coin to be flipped.
-
Output
-
After each group of data is output for K operations, the number of front coins is Nb and the number of reverse coins is sb.
-
Sample Input
-
1
-
5 3
-
1 3
-
2 4
-
3 5
-
Sample output
-
2 3
Simulation questions
#include <stdio.h>main(){int number,te;int a[1000];int opnumber;int temp1,temp2;int coinnumber;int i;int j;int count1,count2;scanf("%d",&number);for(te=1;te<=number;te++){for(i=0;i<1000;i++)a[i]=1;scanf("%d %d",&coinnumber,&opnumber);for(i=0;i<opnumber;i++){scanf("%d %d",&temp1,&temp2);for(j=temp1-1;j<temp2;j++){if(a[j]==1){a[j]=-1;continue;}if(a[j]==-1){a[j]=1;continue;}}}count1=0;count2=0;for(i=0;i<coinnumber;i++){if(a[i]==1)count1++; if(a[i]==-1) count2++;}printf("%d %d\n",count1,count2);}}