首页 > ACM题库 > HDU-杭电 > HDU 3318-Assignment Tools[解题报告]HOJ
2014
03-16

HDU 3318-Assignment Tools[解题报告]HOJ

Assignment Tools

问题描述 :

In Valentine’s Day, lovers usually send gifts to their GF or BF. To express their sincerity, they choose DIY.

Small JH want to make a surprise to his GF, so he finds a shop named “DIY Space”. But there are so many people scramble for tools to make their gifts. To solve the problem, the boss makes a rule:

1.You will not regain the tool until you can complete all things what you need to do.(If someone has all tools he needs, he will complete immediately. Otherwise, he can’t do anything)

2.If the boss has enough tools he will give you when you need tools.

3.You don’t have to queue up.

Small JH should wait until all people leave, because he needs all tools.

People have their tools and never return before completing their tasks. Sometimes it has a state: the boss has no tools any more and everyone can’t get enough tools.

Please tell him whether he should wait.

输入:

The input consist of several cases, please deal with till the end of file. Each case contains two integers N and M (0 < N, M <= 100), representing there are N kinds of tools and M people. Second line there are N integers, N(i) means the boss own Ni number of ith tool(equal to the number of tools Small JH need).Then follow M lines, each consisting N integers, the number in ith row and jth column means the amount of the jth tools that the ith people need. After it there also M lines, each line has N integers too, the number in ith row and jth column means this amount of jth tools have been allotted to the ith people.

The total number of ith tool that all people own will not bigger than boss own at first.

输出:

The input consist of several cases, please deal with till the end of file. Each case contains two integers N and M (0 < N, M <= 100), representing there are N kinds of tools and M people. Second line there are N integers, N(i) means the boss own Ni number of ith tool(equal to the number of tools Small JH need).Then follow M lines, each consisting N integers, the number in ith row and jth column means the amount of the jth tools that the ith people need. After it there also M lines, each line has N integers too, the number in ith row and jth column means this amount of jth tools have been allotted to the ith people.

The total number of ith tool that all people own will not bigger than boss own at first.

样例输入:

2 2
10 11
9 8
5 8
2 3
3 5

2 2
10 10
9 8
5 8
2 3
3 5

样例输出:

Yes
No

/* 
 * File:   main.cpp
 * Author: Kevin
 *
 * Created on 2013年10月27日, 下午2:06
 */

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
int p[105][105][2];
bool flag[105];
int a[105];
  int n,m;
bool jude(int m){
   for(int i=0;i<n;i++){
       if(p[m][i][0]>a[i])return false;
   }   
   return true;
}
bool solve(){
    for(int i=0;i<m;i++){
        if(flag[i]==false&&jude(i)){
            flag[i]=true;
            for(int j=0;j<n;j++){
                a[j]+=p[i][j][1];  
            }
            i=-1;
        }
    }
    for(int i=0;i<m;i++)if(flag[i]==false)return false;
    return true;
}
int main(int argc, char** argv) {
  
    while(~scanf("%d%d",&n,&m)){
        for(int i=0;i<n;i++)
            scanf("%d",a+i);
        memset(flag,false,sizeof(flag));
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++)
                scanf("%d",&p[i][j][0]);
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                scanf("%d",&p[i][j][1]);
                p[i][j][0]-=p[i][j][1];
                a[j]-=p[i][j][1];
            }
        }
        
        if(solve())puts("Yes");
        else puts("No");
        
    }
    return 0;
}

  1. 我还有个问题想请教一下,就是感觉对于新手来说,递归理解起来有些困难,不知有没有什么好的方法或者什么好的建议?

  2. 网站做得很好看,内容也多,全。前段时间在博客园里看到有人说:网页的好坏看字体。觉得微软雅黑的字体很好看,然后现在这个网站也用的这个字体!nice!

  3. I like your publish. It is great to see you verbalize from the coronary heart and clarity on this essential subject matter can be easily noticed.