HNAU First Training Problem NO 考查知识点 hdu题号 problem_name 1001 简单几何题 1086 You can Solve a Geometry Problem too 1002 博弈(DP) 1079 Calendar Game 1003 搜索,递归求解 1026 Ignatius and the Princess I 1004 动态规划 1024 Max Sum Plus Plus 1005 图论 1217 Arbitrage 1006 字典树 1075 What Are You Talking About 1007 网络流 3549 Flow Problem 1008 离散化+线段树 1264 Counting Squares |
解题报告:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
char str[3002];
map<string,string> m;
void deal()
{
string s;
for(int i=0;str[i];i++)
{
s="";
while(str[i]&&str[i]>='a'&&str[i]<='z')
s+=str[i++];
if(s.length()>0)
{
if(m[s].length()>0)
cout<<m[s];
else
cout<<s;
}
if(str[i])printf("%c",str[i]);
}
cout<<endl;
}
int main()
{
char s[20],e[20];
while(~scanf("%s",s))
{
m.clear();
while(1)
{
scanf("%s",s);
if(s[0]=='E')
break;
scanf("%s",e);
m[e]=s;
}
scanf("%s",s);
getchar();
while(1)
{
gets(str);
if(str[0]=='E')break;
deal();
}
}
return 0;
}
Arbitrage
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
map<string,int> m;
double graph[50][50];
void init(int n){
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
graph[i][j]=0;
if(i==j)
graph[i][j]=1;
}
}
void show(int n){
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<graph[i][j]<<" ";
}
cout<<endl;
}
}
void floy(int n)
{
int i,j,k;
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(graph[i][k]*graph[k][j]>graph[i][j])
graph[i][j]=graph[i][k]*graph[k][j];
}
}
int main()
{
int i,n,edge;
char s[40],e[40];
double v;
int x,y,cnt=1;
while(~scanf("%d",&n)&&n)
{
m.clear();
for(i=0;i<n;i++)
{
scanf("%s",s);
m[s]=i;
}
scanf("%d",&edge);
init(n);
for(i=0;i<edge;i++)
{
scanf("%s%lf%s",s,&v,e);
x=m[s];
y=m[e];
graph[x][y]=v;
}
//show(n);
floy(n);
//show(n);
int f=0;
for(i=0;i<n;i++)
if(graph[i][i]>1.0)
{
f=1;break;
}
printf("Case %d: ",cnt++);
if(f)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}