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 1029. Ministry

TL#1
Posted by IgorTuphanov 24 Dec 2005 19:26
Может, я чего и не понимаю, но почему подобный код получает TL#1?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define inf 2100000000

int a[2][510],res[2][510];
char fy[110][510];
int n,m,min,i1,i2;

void Rec(int i, int j)
{
   if (i > 1) {
      if (fy[i][j] == j) Rec(i-1,j); else Rec(i,fy[i][j]);
   };
   printf("%d\n",j);
};

int main(void)
{
   int i,j;

   scanf("%d%d",&m,&n);

   for (j = 1; j <= n; j++) scanf("%d",&a[1][j]);
   for (i = 1; i <= n; i++) res[1][i] = a[1][i];
   for (i = 2; i <= m; i++)
      for (j = 1; j <= n; j++) res[i][j] = inf;

   for (i = 1; i < m; i++) {
      i1 = i%2; i2 = (i+1)%2;
      for (j = 1; j <= n; j++) scanf("%d",&a[i2][j]);
      for (j = 1; j <= n; j++) {
         res[i2][j] = res[i1][j] + a[i2][j]; fy[i+1][j] = j;
      };
      for (j = 2; j <= n; j++)
         if (res[i2][j] > res[i2][j-1] + a[i2][j]) {
            res[i2][j] = res[i2][j-1] + a[i2][j]; fy[i+1][j] = j-1;
         };
      for (j = n-1; j >= 1; j--)
         if (res[i2][j] > res[i2][j+1] + a[i2][j]) {
            res[i2][j] = res[i+1][j+1] + a[i2][j]; fy[i+1][j] = j+1;
         };
      };

   min = inf;
   for (i = 1; i <= n; i++)
      if (res[m%2][i] < min) {
         min = res[m%2][i]; i1 = i;
      };

   Rec(m,i1);
   return 0;
};
Re: TL#1
Posted by Ilian 3 Mar 2014 03:32
Почему scanf и printf. Ты используешь cin и cout. (Because of scanf and printf. It's better to use cin and cout)