pat 秋 Professional Ability Test

7-4

Professional Ability Test

(30分)

Professional Ability Test (PAT) consists of several series of subject tests. Each test is divided into several levels. Level A is a prerequisite (前置要求) of Level B if one must pass Level A with a score no less than SSS in order to be qualified to take Level B. At the mean time, one who passes Level A with a score no less than SSS will receive a voucher(代金券)of DDD yuans (Chinese dollar) for taking Level B.

At the moment, this PAT is only in design and hence people would make up different plans. A plan is NOT consistent if there exists some test T so that T is a prerequisite of itself. Your job is to test each plan and tell if it is a consistent one, and at the mean time, find the easiest way (with minimum total SSS) to obtain the certificate of any subject test. If the easiest way is not unique, find the one that one can win the maximum total value of vouchers.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers NNN (≤1000\le 1000≤1000) and MMM, being the total numbers of tests and prerequisite relations, respectively. Then MMM lines follow, each describes a prerequisite relation in the following format:

T1 T2 S D

where T1 and T2 are the indices (from 0 to N−1N-1N−1) of the two distinct tests; S is the minimum score (in the range (0, 100]) required to pass T1 in order to be qualified to take T2; and D is the value of the voucher (in the range (0, 500]) one can receive if one passes T1 with a score no less than S and plan to take T2. It is guaranteed that at most one pair of S and D are defined for a prerequisite relation.

Then another positive integer KKK (≤N\le N≤N) is given, followed by KKK queries of tests. All the numbers in a line are separated by spaces.

Output Specification:

Print in the first line Okay. if the whole plan is consistent, or Impossible. if not.

If the plan is consistent, for each query of test T, print in a line the easiest way to obtain the certificate of this test, in the format:

T0->T1->...->T

However, if T is the first level of some subject test (with no prerequisite), print You may take test T directly. instead.

If the plan is impossible, for each query of test T, check if one can take it directly or not. If the answer is yes, print in a line You may take test T directly.; or print Error. instead.

Sample Input 1:

8 15
0 1 50 50
1 2 20 20
3 4 90 90
3 7 90 80
4 5 20 20
7 5 10 10
5 6 10 10
0 4 80 60
3 1 50 45
1 4 30 20
1 5 50 20
2 4 10 10
7 2 10 30
2 5 30 20
2 6 40 60
8
0 1 2 3 4 5 6 7

Sample Output 1:

Okay.
You may take test 0 directly.
0->1
0->1->2
You may take test 3 directly.
0->1->2->4
0->1->2->4->5
0->1->2->6
3->7

Sample Input 2:

4 5
0 1 1 10
1 2 2 10
3 0 4 10
3 2 5 10
2 0 3 10
2
3 1

Sample Output 2:

Impossible.
You may take test 3 directly.
Error.

这题只弄到6分 秋季这个题  受益颇多  第一题熊猫那个还没做  这又把晚上搭上了终于过了样例 卑微的要求 哈哈 

这题  主要是信息量 大 有些东西没读清 比如用了个最高级 让我成功忽略了第一标准 还是没练到位

还有没有去标记 天真啊

同起点环的判断  以及更新最大值忘记更新  两个标准只要答案改变 相应的另一个参数值也要改变

还有两个标准的存储  与前后两个节点有关 不是只有一个结点有关 想当然  采用hash 位数存储 效果不错

#include<bits/stdc++.h>
using namespace std;
int book[1000];//crt
vector<int> temp,ans[1000],a[1000];//crt
//zl外面入好第一个 temp  标记 
map<int,int> yr,ff;
int maxsum=-1,minsc=1000000000;

int cnt=0,flagg=0;
void dfs(int index){
	//end
	if(a[index].size()==0){
	int sum=0,sc=0;
	for(int i=1;i<temp.size();i++){
		sum+=yr[temp[i-1]*1000+temp[i]];
		sc+=ff[temp[i-1]*1000+temp[i]];
		//debug
		//printf(" %d",yr[temp[i-1]*1000+temp[i]]); 
	}
	if(sc<minsc){
		minsc=sc;
		//debug
		//printf(" %d",sc);
		ans[cnt]=temp;
		maxsum=sum;//另一个标准只要更新了答案也要更新当前答案 
	}	
	else if(sc==minsc&&sum>maxsum){//第一标准没用上   If the easiest way is not unique, find the one that one can win the maximum total value of vouchers.首先是一个最高级 
		ans[cnt]=temp;
		maxsum=sum;//取最大值又忘记赋值了你要改变最大值 
	}
	temp.pop_back();
	}
	for(int i=0;i<a[index].size();i++){
		if(book[a[index][i]]==0){
			book[a[index][i]]=1;//自己路上  有向图没有说是自己到自己的环到可以有多条不同路径到一个地方的方式 所以还是要去标记 如果在一条路上自己碰到自己不行 
			temp.push_back(a[index][i]);
			//debug
			//printf(" %d",a[index][i]) ;
			dfs(a[index][i]);
			book[a[index][i]]=0;
		}else{
			flagg=1;//多层递归未必能反回 不如设置一个标记  //判断有无回到自己的环 
		}
	}
	if(a[index].size()!=0)temp.pop_back();
}
int main(){
	int n,m,_1,_2,_3,_4;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d%d",&_1,&_2,&_3,&_4);
		a[_2].push_back(_1);
		yr[_2*1000+_1]=_4;
		ff[_2*1000+_1]=_3;
	}
	int k,_5;
	scanf("%d",&k);
	int flag=1;
map<int,int> ok;
	for(int i=0;i<k;i++){
		scanf("%d",&_5);
		temp.clear();
		maxsum=-1; 
		minsc=1000000000;
		flagg=0;
		fill(book,book+1000,0);
		temp.push_back(_5);
		book[_5]=1; 
		dfs(_5);//多层递归返回值可能没用了  还是全局外的标记靠谱注意crt 
		cnt++;
		if(flagg==1){
			flag=-1;
		ok[_5]=1;
		}
	}
	
	if(flag==-1){
		printf("Impossible.\n");
		for(int i=0;i<cnt;i++){
			if(ok[ans[i][0]]==1){
				printf("Error.\n");
			}else{
				if(ans[i].size()==1){
					printf("You may take test %d directly.\n",ans[i][0]);
				}else {
					for(int j=0;j<ans[i].size();j++){
						if(j!=0) printf("->");
						printf("%d",ans[i][ans[i].size()-1-j]);
					}
					printf("\n");
				}
			}
		}
	}else{
		printf("Okay.\n");
		for(int i=0;i<cnt;i++){
	if(ans[i].size()==1){
					printf("You may take test %d directly.\n",ans[i][0]);
				}else {
					for(int j=0;j<ans[i].size();j++){
						if(j!=0) printf("->");
						printf("%d",ans[i][ans[i].size()-1-j]);
					}
					printf("\n");
				}
	       }
	   }
    
	return 0;
}

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值