CSU 1457: Boggle 1458: Booking 1460: Kastenlauf

1457: Boggle

#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long(LL);
typedef unsigned long long(ULL);
const double eps(1e-8);

int score,num;
bool v[5000010],vv[10][10];
int dx[]= {1,1,0,-1,-1,-1,0,1};
int dy[]= {0,1,1,1,0,-1,-1,-1};
int val[]={0,0,0,1,1,2,3,5,11,11,11};
char str[300010][10],Mat[4][5],ans[10],tmp[10];

struct node
{
     node *Next[26];
     int sc,num;
     bool flag;
     node()
     {
           for(int i=0; i<26; ++i) Next[i]=NULL;
           num=0,sc=-1;
     }
} *root;


void Insert(char *s,int id)
{
     node *p=root;
     int i=0,idx;
     while(s[i])
     {
           idx=s[i]-'A';
           if(p->Next[idx]==NULL)
                 p->Next[idx]=new node();
           p=p->Next[idx];
           ++i;
     }
     p->num=id;
     p->sc=val[strlen(s)];
}

void Matching(char *s)
{
     int i=0,idx;
     node *p=root;
     int len=strlen(s);
     while(s[i])
     {
           idx=s[i]-'A';
           if(p->Next[idx]==NULL) break;
           p=p->Next[idx];
           ++i;
     }
     if(v[p->num]==false && p->sc!=-1)
     {
           ++num;
           score+=p->sc;
           v[p->num]=true;
           if(num==1 || (strlen(s)>strlen(ans)) || ((strlen(s)==strlen(ans) && strcmp(s,ans)<0)) )
                 memcpy(ans,s,10);
     }
}

void dfs(int x,int y,int cnt)
{
     if(cnt>8) return;
     tmp[cnt-1]=Mat[x][y];
     tmp[cnt]='\0';
     Matching(tmp);
     vv[x][y]=true;
     for(int i=0;i<8;++i)
     {
           int xx=x+dx[i];
           int yy=y+dy[i];
           if(vv[xx][yy]!=true && (xx>=0&&xx<4&&yy>=0&&yy<4))
           {
                 vv[x][y]=1;
                 dfs(xx,yy,cnt+1);
                 vv[x][y]=0;
           }
     }
     vv[x][y]=0;
}

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     int n,m;
     scanf("%d",&n);
     root=new node();
     for(int i=0; i<n; ++i)
     {
           scanf("%s",str[i]);
           Insert(str[i],i);
     }
     scanf("%d",&m);
     while(m--)
     {
           memset(v,0,sizeof v);
           score=num=0;
           for(int i=0; i<4; ++i)
                 scanf("%s",Mat[i]);
           for(int i=0; i<4; ++i)
                 for(int j=0; j<4; ++j)
                       dfs(i,j,1);
           printf("%d %s %d\n",score,ans,num);
     }
     return 0;
}
/**********************************************************************
	Problem: 1457
	User: 3901140225
	Language: C++
	Result: AC
	Time:2288 ms
	Memory:97904 kb
**********************************************************************/


1458: Booking

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct nnn
{
    int st;
    int et;
}node;
node book[5005];
int cmp(node a,node b)
{
    if(a.st==b.st)
    return a.et<b.et;
    return a.st<b.st;
}
int Fun(int a,int b)
{
    if(a<=b)
    return 0;
    return 1;
}
int main()
{
    int i,i1,j,t,c,b,ans,sy,ey,sm,em,sd,ed,sh,eh;
    int d[14]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    char str[30];
    scanf("%d",&t);
    while(t--)
    {
        ans=1;
        scanf("%d%d",&b,&c);
        for(i=0;i<b;i++)
          {
              scanf("%s",str);
             scanf("%d-%d-%d %d:%d %d-%d-%d %d:%d",&sy,&sm,&sd,&sh,&book[i].st,&ey, &em,&ed, &eh, &book[i].et);
             book[i].st+=(sh*60+(sd-1)*24*60);
             for(i1=2013;i1<=sy; i1++)
             if(i1<sy)
             {
                 book[i].st+=(365*24*60);
                 if(i1%400==0||i1%4==0&&i1%100!=0)
                 book[i].st+=(24*60);
             }
             else
             {
                  if((i1%400==0||i1%4==0&&i1%100!=0)&&2<sm)
                  book[i].st+=(24*60);
                  for(j=1;j<sm; j++)
                  book[i].st+=(d[j]*60*24);
             }
             book[i].et+=(eh*60+c+(ed-1)*24*60);
             for( i1=2013;i1<=ey; i1++)
             if(i1<ey)
             {
                 book[i].et+=(365*24*60);
                 if(i1%400==0||i1%4==0&&i1%100!=0)
                 book[i].et+=(24*60);
             }
             else
             {
                  if((i1%400==0||i1%4==0&&i1%100!=0)&&2<em)
                  book[i].et+=(24*60);
                  for(j=1;j<em; j++)
                  book[i].et+=(d[j]*60*24);
             }
          }
      sort(book,book+b,cmp);
      int tim[5005],k=0;
      tim[k++]=book[0].et;
      for(i=1;i<b;i++)//关建要注意的
      {
          for(j=0;j<k;j++)
          if(Fun(tim[j],book[i].st)==0)
            break;
            if(j==k){
                ans+=1;
                tim[k++]=book[i].et;
            }
            else
            tim[j]=book[i].et;
      }
       printf("%d\n",ans);
    }
    return 0;
}

/**********************************************************************
	Problem: 1458
	User: 3901140225
	Language: C++
	Result: AC
	Time:652 ms
	Memory:2060 kb
**********************************************************************/


1460: Kastenlauf

#include<stdio.h>
#include<queue>
#include<iostream>
using namespace std;
typedef struct nnn
{
    int x,y;
}NODE;
int n;
NODE node[105];
int abs(int a)
{
    return a>0?a:-a;
}
int bfs()
{
    queue<NODE>q;
    NODE p;
    int vist[105]={0};
    q.push(node[1]);
    while(!q.empty())
    {
        p=q.front(); q.pop();
        if(abs(p.x-node[n].x)+abs(p.y-node[n].y)<=1000)
        return 1;
        for(int i=2; i<n; i++)
        if(vist[i]==0&&abs(p.x-node[i].x)+abs(p.y-node[i].y)<=1000)
        {
            vist[i]=1; q.push(node[i]);
        }
    }
    return 0;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        n+=2;
        for(int i=1; i<=n; i++)
        scanf("%d%d",&node[i].x,&node[i].y);
        int flog=bfs();
        printf("%s\n",flog?"happy":"sad");
    }
}


/**********************************************************************
	Problem: 1460
	User: 3901140225
	Language: C++
	Result: AC
	Time:4 ms
	Memory:2024 kb
**********************************************************************/

猜你喜欢

转载自blog.csdn.net/nameofcsdn/article/details/80267430