11659 - Informants
Posted: Mon Sep 07, 2009 10:14 am
how to solve this problem ?
Can you post links to similar problems.
Can you post links to similar problems.
Code: Select all
20 0
0 0
dfs()
for each person ,
assume he is speaking truth,
-> All reliables are speaking truth
dfs(for each reliable)
if he is false
do nothing.
Can you tell me how we get 2 informans as reliable ? how would you approach the above example. Any similar problems ?As an example, let's assume there are four informants A, B, C and D, with the following surveyed answers: ``A says B is reliable but D is not'', ``B says C is not reliable'', and ``C says A and D are reliable''. In this case, it happens that at most two informants are reliable.
It is simple, in ther first step all informants are reliable, then A says B is reliable bit D is not, so we got all informants reliable except D, then B wich is reliable says than C is not reliable, so we got A,B reliable and C,D not reliable, then C says that A and D are reliable, but since C is not reliable we should ignore what he or she is saying.tryit1 wrote:Can you tell me how we get 2 informans as reliable ? how would you approach the above example. Any similar problems ?As an example, let's assume there are four informants A, B, C and D, with the following surveyed answers: ``A says B is reliable but D is not'', ``B says C is not reliable'', and ``C says A and D are reliable''. In this case, it happens that at most two informants are reliable.
Ithink it is a easy problem
But I got WA........![]()
![]()
Some one PLZ check my code.........
Code: Select all
#include<stdio.h>
#include<stdlib.h>
int a[803];
int main()
{
int i,n,b,c,m,Count,j,d;
while(scanf("%d%d",&m,&n)==2 && (m || n))
{
Count= 0;
for(i=1;i<=m;i++)
a[i]=1;
for(i=1;i<=n;i++)
{
scanf("%d%d",&b,&c);
if(a[b])
{
if( c > 0)
{
a[c] = 1;
}
else if(c < 0)
{
d = (-1)*c;
a[d] = 0;
}
}
}
for(i=1;i<=m;i++)
{
if(a[i])
Count++;
}
printf("%d\n",Count);
}
return 0;
}
Code: Select all
20 6
1 -3
2 -3
3 1
2 2
7 -1
4 3
Thanks hasan3050 for ur test case
I solve this test case But again WA
My modified code Here:
PLZ help me.....
Code: Select all
#include<stdio.h>
#include<stdlib.h>
int a[803];
int main()
{
int i,n,b,c,m,Count,d,e;
//freopen("a.txt","r",stdin);
while(scanf("%d%d",&m,&n)==2 && (m || n))
{
Count= 0;
for(i=1;i<=m;i++)
a[i]=1;
for(i=1;i<=n;i++)
{
scanf("%d%d",&b,&c);
e = c;
if( e < 0)
{
e = (-1)*e;
}
if( (a[b]==2) && ( a[e] > 0) )
{
if( c > 0)
{
a[c] = 2;
}
else if(c < 0)
{
a[e] = 0;
}
}
else if( (a[b]==1) && ( a[e] > 0) )
{
if( c > 0)
{
a[c] = 2;
}
else if(c < 0)
{
a[e] = 0;
}
}
}
for(i=1;i<=m;i++)
{
//printf("a [%d] == %d\n",i,a[i]);
if(a[i]>=1)
Count++;
}
printf("\n%d\n",Count);
}
return 0;
}
Code: Select all
3 2
1 -3
3 -2
0 0
"tryit1": can you put problem name when you creating new thread.tryit1 wrote:how to solve this problem ?
Can you post links to similar problems.
how could the answer be 1 !!!!!Igor9669 wrote:First you print leading new line!
Second why do you use such a big array you need only 20 elements and third try this test:Answer should be 1!Code: Select all
3 2 1 -3 3 -2 0 0
I think that the problem says that when an informant is not reliable, their words can be true or false, so I don't se a way of how 2 is not relieabe.Jehad Uddin wrote:because 3 isnt reliable and 2 isnt reliable ,so only 1 is reliable so ans is 1,its so simple problem,try all the I/Os in the board,![]()
![]()