离散题目13

来源:互联网 发布:sqlite数据库加密 编辑:程序博客网 时间:2024/06/18 06:35

离散题目13
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
DaYu平时只顾着看电影,没有学习离散,学期末快考试的时候才慌了神,因为时间不够,因此他决定只复习一个知识点,但是他发现他一个知识点都不会,因此他跑过来请你帮他解决一个问题。求一个集合是否是自反的。
Input
第一行输入组数T(T<10),每组的第一行输入集合元素个数m(m < 100)和对应关系个数n(n < 100),集合中元素为1,2,…,m,接下来n行每行输入两个数x,y(0 < x, y < 100)
Output
如果满足自反关系,则输出true,否则输出false。
Example Input
2
5 9
1 1
1 2
2 2
3 3
2 3
4 4
4 5
5 5
5 1
5 8
1 1
1 2
2 2
3 3
2 3
4 4
4 5
5 1
Example Output
true
false

Think:判断是否满足自反的定义

#include <stdio.h>#include <string.h>int main(){    int t,n,m;    scanf("%d",&t);    int x,y;    while(t--){        scanf("%d%d",&n,&m);        int count=0;        for (int i=0;i<m;i++){            scanf("%d%d",&x,&y);            if (x==y&&x<=n&&y<=n){                count++;            }        }        if (count==n){            printf("true\n");        }        else{            printf("false\n");        }    }    return 0;}