Pearl (Bead)

Source: Internet
Author: User

Title Description

       
give you a balance to compare the weight of a pearl, We can compare two pearls which are heavier, and after making a series of comparisons, we can take away some pearls that certainly do not have the middle weight.

1, Pearl 2 than Pearl 1 weight
2, Pearl 4 than Pearl 3 weight
3, pearl 5 than Pearl 1 weight
4, pearl 4 than Pearl 2 weight

write a program that counts how many pearls are definitely not the middle weight.

input/output format

Input Description:

The first line of the input file contains two spaces separated by integers n and M, where 1<=n<=99, and N is odd, M is the number of comparisons to pearls, and the next m row contains two integers separated by spaces X and Y, indicating that Pearl X is heavier than Pearl Y.

Output Description:

The output file contains only one line with an integer representing the total number of pearls that cannot be the middle weight.

input/Output sample

Input Sample # #:

5 42 14 35 14 2

Sample # # of output:

2
Ideas

Enter the data first, then the size of each number according to the comparison, and finally the number of impossible pearls output.

Code
#include <stdio.h>inta[ -][ -],b[3][ -]={0};intMain () {intn,i,m,j,k=0, S; scanf ("%d%d",&n,&m);  for(i=1; i<=m;i++)        for(j=1; j<=2; j + +) scanf ("%d",&A[i][j]); S=n/2+1;  for(i=1; i<=m;i++) {b[a[i][1]][1]=a[i][1]; b[a[i][1]][3]++; b[a[i][2]][1]=a[i][2]; b[a[i][2]][2]++; }     for(i=1; i<=m;i++) {b[a[i][1]][3]=b[a[i][1]][3]+b[a[i][2]][3]; b[a[i][2]][2]=b[a[i][2]][2]+b[a[i][1]][2]; }     for(i=1; i<=n;i++)      if(b[i][2]>=s| | b[i][3]>=s) k++; printf ("%d", K); return 0;}
View Code

Pearl (Bead)

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.