1.
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: 11659 - Informants
* Link: http://uva.onlinejudge.org/external/116/11659.pdf
*
* @author Philippe Brousse
* @version 1.0, 10/27/2010
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.444
*/
package informants;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author Philippe Brousse
*/
public class Main
{
/**
* @param Kommandozeilenargumente
*/
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int informants;
int statements;
while (true)
{
informants = input.nextInt();
statements = input.nextInt();
//Ende erreicht bei Eingabe 0 0
if (informants == 0 && statements == 0)
{
input.close();
return;
}
//Wer sagt was?
boolean[] reliable = new boolean[informants];
for (int i = 0; i < informants; i++)
{
reliable[i] = true;
}
for (int i = 0; i < statements; i++)
{
int inf = input.nextInt();
int stat = input.nextInt();
if (stat < 0)
{
reliable[-stat - 1] = false;
}
}
int rel = 0;
for (boolean b : reliable)
{
if (b)
{
rel++;
}
}
System.out.println(rel);
}
}
}
2.
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11659 - Informants
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2706
*
* @author Evgeni Pavlidis
* @version 1.0, 06/02/2010
*
* Method : Ad hoc
* Status : Accepted
* Runtime: 0.352
*/
import java.io.*;
import java.util.*;
class Main {
public static void main(String...args)
{
Scanner sc = new Scanner(System.in);
int i,a, x,y;
while(true)
{
i = sc.nextInt();
a = sc.nextInt();
if( a == 0 && i == 0)
break;
boolean[] reliable = new boolean[i+1];
for(int p = 1; p <= i; p++)
reliable[p] = true;
for(int ans = 0; ans < a; ans++)
{
x = sc.nextInt();
y = sc.nextInt();
if( y < 0)
reliable[-y] = false;
}
int c = 0;
for(int p = 1; p <= i; p++)
if(reliable[p])
c++;
System.out.println(c);
}
}
}
2.
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11659 - Informants
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2706
*
* @author Siegfried Ippisch
* @version 1.0, 09/06/2010
*
* Method : Ad hoc
* Status : Accepted
* Runtime: 0.396
*/
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
while(true){
int count = input.nextInt();
int answers = input.nextInt();
// informants Array, on start all are reliable
boolean[] informants = new boolean[count+1];
for(int i=1; i<=count; i++)
informants[i] = true;
// number of answers
if(answers == 0 && count == 0)
break;
// if informant reliable -> change state of other informant
for(int i=0; i<answers; i++){
int x = input.nextInt();
int y = input.nextInt();
if(y<0)
informants[-y] = false;
}
// count all reliable informants
int c = 0;
for(int i=1; i<=count; i++)
if(informants[i])
c++;
System.out.println(c);
}
input.close();
}
}