2010年9月17日 星期五

ACM 10919 - Prerequisites?

#include <stdio.h>
#define SIZE 101

int classID[SIZE];
int index, n, m, c, r;

int getInt()
{
char ch;
int n = 0;
while( ch = getchar())
if(ch != ' ' && ch != '\n') break;
n = ch - 48;
while( ch = getchar())
{
if(ch == ' ' || ch == '\n') break;
n = n * 10 + ch - 48;
}
return n;
}

int isFind(int low, int high, int n)
{
int mid;
if (low > high) return -1;
else
{
mid = (low + high) / 2;
if (n == classID[mid])
return mid;
else if (n < classID[mid])
return isFind(low, mid - 1, n);
else
return isFind(mid + 1, high, n);
}
}

int main()
{
int id, i, tmp;
while ((n = getInt()))
{
index = 0;
m = getInt();
while (n --)
{
id = getInt();
classID[index] = id;
for (i = index; i >= 1; i --)
if (classID[i] < classID[i - 1])
tmp = classID[i], classID[i] = classID[i - 1], classID[i - 1] = tmp;
else break;
index ++;
}
int error = 0, f;
while (m --)
{
c = getInt(), r = getInt();
int count = 0, find;
while (c --)
{
f = getInt();
find = isFind(0, index, f);
if (find != -1) count ++;
}
if (count < r) error = 1;
}
if (error) puts("no");
else puts("yes");
}
return 0;
}


回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...