zoukankan      html  css  js  c++  java
  • hoj 13788 Dwarves

    //首先判环我都不会 dfs实在写的戳 后来测了好多数据发现dfs写错了 唉 其次不会哈希啊 这个哈希还是dalao手写给我的 珍惜!!!
    #include <iostream> #include <algorithm> #include <stdio.h> #include <vector> #include <string> #include <string.h> #include <queue> #include <math.h> #include <map> #define ULL unsigned long long using namespace std; const int maxn=10010; const int INF=0x3f3f3f3f; #define mod 10007 int cnt; vector <int> e[10010]; //map<ULL,int> mp; int f[10010]; int de[maxn]; int tot; bool flag=true; void dfs(int now){ f[now]=-1; for(int i=0;i<e[now].size();i++) { if(f[e[now][i]]==-1) {flag=false;} else if(f[e[now][i]]==0) dfs(e[now][i]); } f[now]=1; } const int maxbuf = 11111; struct node { ULL key; int id,next; }buf[maxbuf]; int h[maxn]; ULL fuck(char a[30]){ ULL ha=0; for(int i=0;a[i];i++){ ha*=52; ha+=a[i]; } return (ha); } void inithash() { tot = 0; memset(h,-1,sizeof(h)); } int ins(ULL key) { int now = ++tot; buf[now].key = key, buf[now].id = now, buf[now].next = h[key%mod]; h[key%mod] = now; return now; } int fnd(ULL key) { for (int i=h[key%mod];~i;i=buf[i].next) { if (buf[i].key == key) return buf[i].id; } return 0; } char s1[30],s2[30]; int main(){ #ifdef shuaishuai freopen("C:\Users\hasee\Desktop\trianglen=100000.in","r",stdin); // freopen("C:\Users\hasee\Desktop\b.txt","w",stdout); // freopen("C:\Users\hasee\Desktop\picture.in","r",stdin); #endif // ios::sync_with_stdio(false); char s; int n; memset(f,0,sizeof f); memset(de,0,sizeof de); inithash(); while(scanf("%d ",&n)!=EOF) { cnt=1; for(int i=0;i<n;i++) { // cout<<"@"<<endl; scanf("%s %c %s ",s1,&s,s2); // cout<<s1<<" "<<s<<" "<<s2<<endl; ULL x1=fuck(s1); ULL x2=fuck(s2); int u = fnd(x1), v = fnd(x2); // cout<<"before "<<u<<" "<<v<<" "<<tot<<endl; // cout<<x1<<" "<<x2<<endl; if (!u) u = ins(x1); if (!v) v = ins(x2); // printf("%s %d %s %d ",s1,u,s2,v); // cout<<u<<" "<<v<<" "<<tot<<endl; // printf("%d %d ",x1,x2); // int x1=mp[t1],x2=mp[t2]; // if(x1==0)x1=mp[t1]=cnt++; // if(x2==0)x2=mp[t2]=cnt++; if(s=='>') { e[u].push_back(v); de[v]++; } else { e[v].push_back(u); de[u]++; } } for(int i=1;i<=tot;i++ ){ if(f[i]==0) dfs(i); if(!flag) break; } if(flag) printf("possible "); else printf("impossible "); for(int i=0;i<=tot;i++)e[i].clear(),f[i]=0,h[i]=-1,de[i]=0; tot=0; } return 0; }
  • 相关阅读:
    [BZOJ1013][JSOI2008]球形空间产生器sphere 高斯消元
    [Luogu1848][USACO12OPEN]书架Bookshelf DP+set+决策单调性
    [BZOJ1025][SCOI2009]游戏 DP+置换群
    [BZOJ1024][SCOI2009]生日快乐 搜索
    [BZOJ2002][Hnoi2010]Bounce弹飞绵羊 LCT
    「BZOJ 4565」「HAOI 2016」字符合并「区间状压DP」
    「BZOJ 5161」最长上升子序列「状压DP」
    「SPOJ TTM 」To the moon「标记永久化」
    「学习笔记」字符串大礼包
    「CF724G」Xor-matic Number of the Graph「线性基」
  • 原文地址:https://www.cnblogs.com/MeowMeowMeow/p/7277017.html
Copyright © 2011-2022 走看看