HDU 4724 If You Know This,You Must Have NO GF 解题报告
来源:互联网 发布:iphone改铃声软件 编辑:程序博客网 时间:2024/06/05 11:30
题目
题意:
Make一个文件有三种命令:
1、形如Target: [component ...],表示要生成Target,必须要先有所有的components,如果某个component还不存在,就先生成它。如果还是不行,就不生成Target。依赖关系不会成环。
2、形如g++ a.o b.o -o main,完全可以忽略。
3、如果行中有‘#’,则‘#’后的是注释,不用管。
如果一行最后有‘\',表示和下一行是连在一起的,原本是同一行。
这里的“This command will not get executed“有歧义,如果不能执行,究竟还是否生成那些能生成的components?我是能生成则生成,据说热身赛当天的标程是生成到第一个不能生成的component就停止。
题解:
就一个模拟,将文件名分离出来,用数字代替,然后就会得到一棵依赖树,dfs一遍即可。
//Time:31ms//Memory:372KB//Length:2361B#include <cstdio>#include <cstdlib>#include <cstring>#include <string>#include <algorithm>#include <map>using namespace std;#define MAXN 10005map<string,int> ma;int he[MAXN],to[MAXN],nex[MAXN],ntop,ans;char s1[MAXN],s2[MAXN],*s3;bool vi[600],ty[200];void add(int u,int v){ to[ntop]=v; nex[ntop]=he[u]; he[u]=ntop++;}bool cal(int h){ bool flag=true,f2=false; if(vi[h]) return true; for(int i=he[h];i!=-1;i=nex[i]) flag&=cal(to[i]),f2=true; vi[h]=flag&&f2; ans+=flag&&f2; return vi[h];}char *mget(char *s){ if(s==NULL) return NULL; for(int i=0,j=0;s[i]&&s[i]!='#';++i) if(ty[s[i]]) { for(;ty[s[i+j]];++j) s2[j]=s[i+j]; s2[j]='\0'; return s+i+j; } return NULL;}int main(){ //freopen("/home/moor/Code/input","r",stdin); int ncase,len,q,top,now; scanf("%d",&ncase); memset(ty,0,sizeof(ty)); for(int i=0;i<26;++i) ty[i+'a']=ty[i+'A']=1; for(int i=0;i<10;++i) ty[i+'0']=1; ty['.']=1; for (int hh=1;hh<=ncase;++hh) { ntop=0; top=1; memset(he,-1,sizeof(he)); memset(vi,0,sizeof(vi)); ma.clear(); printf("%sCase #%d:\n",hh>1?"\n":"",hh); s1[0]='\0'; while(gets(s1)&&(s1[0]=='\0'||s1[0]=='\n'||s1[0]=='\r')); while(s1[0]!='=') { len=strlen(s1); while(s1[len-1]=='\\') { gets(s2); strcpy(&s1[len-1],s2); len+=strlen(s2)-1; } if(strstr(s1,":")==NULL) { gets(s1); continue; } s3=s1; s3=mget(s3); if(ma.find(s2)==ma.end()) ma[s2]=top++; now=ma[s2]; while((s3=mget(s3))!=NULL) { if(ma.find(s2)==ma.end()) ma[s2]=top++; add(now,ma[s2]); } gets(s1); } scanf("%d",&q); while(q--) { scanf("%s",s1); if(ma.find(s1)!=ma.end()) vi[ma[s1]]=1; } scanf("%d",&q); while(q--) { ans=0; scanf("%s%s",s1,s2); printf("%d\n",ma.find(s2)!=ma.end()?(cal(ma[s2])?ans:0):0); } gets(s1); } return 0;}
- HDU 4724 If You Know This,You Must Have NO GF 解题报告
- acm解题报告 HDU 2199 Can you solve this equation?
- You should blog even if you have no readers
- You should blog even if you have no readers。
- You should blog even if you have no readers
- You should blog even if you have no readers
- You should blog even if you have no readers
- 5 algorithms you must know
- HDU 4723 How Long Do You Have to Draw 解题报告
- No goals have been specified for this build. You must specify a valid li fecycle phase or a goal in
- No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in t
- Maven不让编译: No goals have been specified for this build. You must specify a valid lifecy
- Maven报错 解决方案。ERROR: No goals have been specified for this build. You must specify a valid lifecycle
- you must have a uni
- did you know this translate?
- You should blog even if you have no readers--Nathan Marz
- 即使没有读者,你应该写博客(You should blog even if you have no readers)
- 即使没有读者,你应该写博客(You should blog even if you have no readers)
- POJ 2533 Longest Ordered Subsequence
- join用法实际上就是implode()
- 杭电3469---简单二维背包!!
- Codeforce #145A Cinema
- 容器<一>
- HDU 4724 If You Know This,You Must Have NO GF 解题报告
- hdu 1230 火星A+B
- 引用作为返回值的注意事项
- Java学习笔记10 —— 类的构造函数
- 浏览器输入网址后台是如何运作的
- Code Sign error: Provisioning profile 'xxx' can't be found
- Codeforces Round #198 (Div. 2) B. Maximal Area Quadrilateral
- Ubuntu10.04 挂载硬盘windows分区时提示输入密码
- PowerPoint