Codeforces 787B Not Afraid( 水 )


**链接:****传送门 **

题意:判断 m 组数,如果某一组中出现负数就判断这一组中是否存在与之相反的数,如果每一组中都满足要求则输出 "NO" 反之输出 "YES"

思路:对于任意的一组数,if v[i] < 0 则 vector.find( v.begin() , v.end() , -v[i] )查一下在这组数中是否出现过相反数,如果 find != v.end() 说明出现过,返回 true 否则返回一个 false


/*************************************************************************
    > File Name: Codeforces787B.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017年05月25日 星期四 11时23分40秒
 ************************************************************************/

#include<bits/stdc++.h>
using namespace std;

// #define pb(x) push_back(x)

vector<int> V;

bool check(){
	int len = V.size();
	for(int i = 0 ; i < len ; i++){
		if( V[i] < 0 ){
			if( find( V.begin() , V.end() , -V[i] ) != V.end() )		// 如果找到一对相反数
				return true;
		}
	}
	return false;
}
int main(){
	int n , m , k , x;
	bool ok = true;
	scanf("%d%d",&n,&m);
	for(int i = 0 ; i < m ; i++){
		V.clear();
		scanf("%d",&k);
		for(int j = 0 ; j < k ; j++){
			scanf("%d",&x);		V.push_back(x);
		}
		if(!check())	ok = false;
	}
	if(ok)	printf("NO\n");
	else		printf("YES\n");
	return 0;
}
posted @ 2017-05-25 12:31  ojnQ  阅读(216)  评论(0编辑  收藏  举报