ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1042. Central Heating

Why my program got WA?
Posted by yellowgreen(*Jane*)^_^ 2 Apr 2003 17:51
#include<stdio.h>
#include<string.h>

#define max 251

int n,total,note[max][max],result[max];

void init()
{
  int i,j,t;
  memset(note,0,sizeof(note));
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&t);
      while(t!=-1)
    {
      note[t][i]=1;note[t][0]=1;
      scanf("%d",&t);
    }
    }
}

int judge()
{
  int i;
  for(i=1;i<=n;i++)
    if(!note[i][0])return 1;
  return 0;
}

void change(int a,int b)
{
  int i,temp[max];
  for(i=1;i<=n;i++)temp[i]=note[a][i];
  for(i=1;i<=n;i++)note[a][i]=note[b][i];
  for(i=1;i<=n;i++)note[b][i]=temp[i];
}

void find(int a,int s)
{
  int i,j;
  for(i=s+1;i<=n;i++)
    if(note[i][a])
      {
    note[i][0]=(note[i][0]+note[s][0])%2;
    for(j=1;j<=n;j++)
      note[i][j]=(note[i][j]+note[s][j])%2;
      }
}

void work()
{
  int i,j,sum;
  if(judge()){total=1;return;}else total=0;
  for(i=1;i<=n;i++)
    {
      for(j=i;j<=n;j++)if(note[j][i])break;
      change(i,j);
      find(i,j);
    }
  for(i=n;i>0;i--)
    {
      if(!note[i][i]){total=1;return;}
      sum=note[i][0];
      for(j=i+1;j<=n;j++)if(note[i][j])sum+=result[j];
      result[i]=sum%2;
    }
}

void out()
{
  int i,j;
  if(total)printf("No solution\n");
  else
    {
      for(i=1;i<=n;i++)
    if(result[i])break;
      if(result[i])printf("%d",i);
      for(j=i+1;j<=n;j++)
    if(result[j])
      printf(" %d",j);
      printf("\n");
    }
}

int main()
{
  init();
  work();
  out();
  return 0;
}
Why my program still WA?Please help me!Thank you!
Posted by yellowgreen(*Jane*)^_^ 2 Apr 2003 19:31
#include<stdio.h>
#include<string.h>

#define max 300

int n,total,note[max][max],result[max];

void init()
{
  int i,j,t;
  memset(note,0,sizeof(note));
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&t);
      while(t!=-1)
    {
      note[t][i]=(note[t][i]+1)%2;note[t][0]=1;
      scanf("%d",&t);
    }
    }
}

int judge()
{
  int i;
  for(i=1;i<=n;i++)
    if(!note[i][0])return 1;
  return 0;
}

void change(int a,int b)
{
  int i,temp;
  for(i=1;i<=n;i++)
    {
      temp=note[a][i];
      note[a][i]=note[b][i];
      note[b][i]=temp;
    }
}

void find(int s)
{
  int i,j;
  for(i=s+1;i<=n;i++)
    if(note[i][s])
      {
    for(j=0;j<=n;j++)
      note[i][j]=(note[i][j]+note[s][j])%2;
      }
}

void work()
{
  int i,j,sum;
  if(judge()){total=1;return;}else total=0;
  for(i=1;i<=n;i++)
    {
      for(j=i;j<=n;j++)if(note[j][i])break;
      change(i,j);
      find(i);
    }
  for(i=n;i>0;i--)
    {
      if(!note[i][i]){total=1;return;}
      sum=note[i][0];
      for(j=i+1;j<=n;j++)if(note[i][j])sum+=result[j];
      result[i]=sum%2;
    }
}

void out()
{
  int i,j;
  if(total)printf("No solution\n");
  else
    {
      for(i=1;i<=n;i++)
    if(result[i])break;
      if(result[i])printf("%d",i);
      for(j=i+1;j<=n;j++)
    if(result[j])
      printf(" %d",j);
      printf("\n");
    }
}

int main()
{
  init();
  work();
  out();
  return 0;
}
Your Gauss Jordan Method is totally incorrect (-)
Posted by Miguel Angel 3 Apr 2003 05:15
[code deleted]

Edited by moderator 09.12.2019 18:47
I've Ac now!
Posted by yellowgreen(*Jane*)^_^ 3 Apr 2003 13:07
[code deleted]

Edited by moderator 09.12.2019 18:47