HNAU_FirstTraining

本文提供了HNAU首次训练中的八道题目的详细解答,涵盖了简单的几何问题、博弈论、搜索算法、动态规划、图论、字典树、网络流及离散化加线段树等算法。通过具体的代码示例展示了如何使用C++实现这些算法解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值