1349 coin game

Source: Internet
Author: User
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);}}

 

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.