Poj 2947 Widget Factory (Gaussian elimination element Jiantong equation)

Source: Internet
Author: User

Topic Connection:

http://poj.org/problem?id=2947

Main topic:

There are n types of parts, m workers, each part of the processing time is [3,9], each worker in a specific time period can produce K parts (can be the same type, but also different types), ask each of the parts to produce a time to come out?

Problem Solving Ideas:

The given time period is from weeks to weeks, and does not give a specific time period, so in the calculation process to take the mold, there is to each part to be within the scope of the topic to enumerate.

PS: If the augmented matrix is n*n, but there is no reasonable solution for a part in [3,9], it is also non-solution.

1#include <cmath>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 Const intMAXN =310;8 intDET[MAXN][MAXN], RES[MAXN],var, equ;9 Charstr[Ten][Ten] = {"","MON","TUE","WED","THU","FRI","SAT","SUN"};Ten intDay (Chars[]) One { A      for(intI=1; i<8; i++) -         if(strcmp (S, str[i]) = =0) -             returni; the } - intGauss () - { -     intCol, K; +      for(k=col=0; k<equ&&col<var; k++, col++) -     { +         intMax_i =K; A          for(inti=k+1; i<equ; i++) at             if(ABS (Det[i][col]) >ABS (Det[max_i][col])) -Max_i =i; -         if(Max_i! =k) -              for(intI=col; i<=var; i++) - swap (Det[k][i], det[max_i][i]); -         if(Det[k][col] = =0) in         { -K--; to             Continue; +         } -          for(inti=k+1; i<equ; i++) the             if(Det[i][col]) *             { $                 intx =Det[i][col];Panax Notoginseng                 inty =Det[k][col]; -                  for(intJ=col; j<=var; J + +) theDET[I][J] = ((det[i][j]*y-det[k][j]*x)%7+7) %7; +             } A     } the     inttemp =0, I, J; +      for(i=0; i<equ; i++) -     { $          for(j=0; j<var; J + +) $             if(Det[i][j]) -                  Break; -         if(J = =var) the         { -             if(Det[i][j])Wuyi                 return 0;//no solution for augmented matrices the             Else if(I <var)//The existence of indeterminate variable in augmented matrix -Temp + +; Wu         } -     } About     if(Temp | |var>equ) $         return 1;//The existence of indeterminate variable in augmented matrix -  -      for(i=var-1; i>=0; i--) -     { Atemp =0; +          for(j=i+1; j<var; J + +) theTemp = (temp + det[i][j] * res[j])%7; -          for(j=3; j<Ten; J + +)//enumerate the machining duration of each part $             if(temp + det[i][i]*j)%7= = det[i][var]) the             { theRes[i] =J; the                  Break; the             } -         if(J = =Ten)//when there is a part of the processing time is not between [3,9], then does not conform to test instructions, no solution in             return 0; the     } the     return 2; About } the intMain () the { the      while(SCANF ("%d%d", &var, &equ),var+equ) +     { -         intk, X; the         CharST[MAXN], ET[MAXN];Bayimemset (Det,0,sizeof(DET)); the          for(intI=0; i<equ; i++) the         { -scanf ("%d%s %s", &K, St, ET); -              while(K--) the             { thescanf ("%d", &x); thedet[i][x-1] ++; the             } -det[i][var] = Day (ET) – Day (ST) +1; the         } the          for(intI=0; i<equ; i++)//here must go to the second Yu, if DET[I][J] is a multiple of 7, in the process of the step array is likely to be wrong the              for(intj=0; j<=var; J + +)94DET[I][J] = (Det[i][j]%7+7) %7; the         intAns =Gauss (); the         if(ans = =0) theprintf ("inconsistent data.\n");98         Else if(ans = =1) Aboutprintf ("multiple solutions.\n"); -         Else101              for(intI=0; i<var; i++)102printf ("%d%c", Res[i], i==var-1?'\ n':' ');103     }104     return 0; the}

Poj 2947 Widget Factory (Gaussian elimination element Jiantong equation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.