hdu 1251 統計難題 (map水過),hdu1251

來源:互聯網
上載者:User

hdu 1251 統計難題 (map水過),hdu1251

# include <stdio.h># include <algorithm># include <string># include <map># include <iostream>using namespace std;int main(){    char a;    string  x;    map<string,int>q;    while(true)    {        scanf("%c",&a);        if(a=='\n')        {            scanf("%c",&a);            x="";//一個結束x初始化        }        if(a=='\n')//連續兩個\n結束了母串的輸入            break;        x+=a;        q[x]+=1;    }    while(cin>>x)        printf("%d\n",q[x]);    return 0;}


hdu 1251 釋放字典樹時Runtime Error(ACCESS_VIOLATION),指點

//釋放記憶體
void Freedom(Node* p)
{
int i;
for(i=0;i<26;i++){
if(p->Next[i]!=NULL)
Freedom(p->Next[i]);
}
delete p;
}
 
hdu 水題1004,我用map做的,怎就是wa??

赤裸的BFS,但是要注意下標記,得用x,y,t三維標記。因為有些座標有經過多次來重設炸彈。。
貼下My Code。。
#include<stdio.h>
struct queue
{
int x;
int y;
int time;
int t;
}a[200000];
int si,sj,ei,ej,n,m,d[4][2]=;
int map[10][10],hash[10][10][10];
int bfs()
{
int i,x1,y1,t1,head,tail;
a[0].x=si;
a[0].y=sj;
a[0].time=0;
a[0].t=6;
head=0;tail=1;
while(head<tail)
{
// printf("\n%d %d %d %d\n",a[head].x,a[head].y,a[head].time,a[head].t);
// printf("-----------------------------------\n");

for(i=0;i<4;i++)
{
if(a[head].t<2)
break;
x1=a[head].x+d[i][0];
y1=a[head].y+d[i][1];
if(map[x1][y1]==4)
t1=6;
else
t1=a[head].t-1;
if(hash[x1][y1][t1])
continue;
if(x1<0||x1>=n||y1<0||y1>=m)
continue;
if(map[x1][y1]==0)
continue;
a[tail].x=x1;
a[tail].y=y1;
a[tail].t=t1;
a[tail].time=a[head].time+1;
hash[x1][y1][a[tail].t]=1; //注意這裡的標記。
// printf("%d %d %d %d\n",a[tail].x,a[tail].y,a[tail].time,a[tail].t);
if(x1==ei&&y1==ej)
return (a[head].time+1);
tail++;
}
// printf("\n");
head++;
}
return 0;
}

int main()
{
......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.