P1006:模拟

然而我的同余方程能过样例然而就是WA⊙﹏⊙b

【已查明:扩展欧几里得算法出了很隐蔽的问题】

 int exGcd(int x,int y,int& a,int& b) //ax+by=gcd(x,y)
 {
     ; b=; return x; }
     int res=exGcd(y,x%y,a,b);
     int t=a; a=b; b=t-x/y*b;
     return res;
 }

Correct exGcd Code

 #include <cstdio>
 #include <cstring>
 #include <algorithm>

 inline int code(char x)
 {
     switch(x)
     {
     ;
     ;
     ;
     }
 }

 inline char decode(int x)
 {
     switch(x)
     {
      : return '_';
     : return '.';
     ;
     }
 }

 int K;
 ;
 ;

 char cpt[maxL];

 bool input()
 {
     scanf("%d",&K);
     if(!K) return false;
     return scanf("%s",cpt);
 }

 int exGcd(int x,int y,int& a,int& b) //ax+by=gcd(x,y)
 {
     ; b=; return x; }
     int res=exGcd(y,x%y,a,b);
     int t=a; a=b; b=t-b*x/y;
     return res;
 }

 int mdEq(int a,int b,int m) //ax=b(mod m)
 {
     //let ax+km=b
     int x,k;
     int g=exGcd(a,m,x,k);
     x*=(b/g); x%=m;
     ?x+m:x;
 }

 void solve()
 {
     int l=strlen(cpt);
     ;j<l;j++)
     {
         int i=mdEq(K,j,l);
         putchar(decode((i+code(cpt[i]))%apb));
     }
     putchar('\n');
 }

 int main()
 {
     while(input()) solve();
     ;
 }

Problem:ZOJ P1006 WA

P1008:DFS,迷之TLE*2
 #include <cstdio>
 #include <cstring>
 #include <algorithm>

 ],down[],left[],right[];
 ];
 ];
 int N,Ns;

 bool input()
 {
     scanf("%d",&N); Ns=N*N;
     if(!N) return false;
     ;i<=Ns;i++)
         scanf("%d%d%d%d",up+i,right+i,down+i,left+i);
     return true;
 }

 bool move(int,int);
 bool dfs(int);

 inline bool move(int cur,int i)
 {
     used[i]=true;
     fill[cur]=i;
     )) return true;
     used[i]=false;
     return false;
 }

 bool dfs(int cur)
 {
     ) return true;
     bool res=false;
     ;
     ;
     ) st|=;
     ;i<=Ns;i++)
         if(!used[i])
         {
             )
             {
                 res=move(cur,i);
                 if(res) return true;
             }
             )
             {
                 int& u=fill[cur-N];
                 if(up[i]==down[u])
                 {
                     res=move(cur,i);
                     if(res) return true;
                 }
             }
             )
             {
                 ];
                 if(left[i]==right[l])
                 {
                     res=move(cur,i);
                     if(res) return true;
                 }
             }
             else
             {
                 int& u=fill[cur-N];
                 ];
                 if(left[i]==right[l] && up[i]==down[u])
                 {
                     res=move(cur,i);
                     if(res) return true;
                 }
             }
         }
     return false;
 }

 int main()
 {
     );
     freopen("t.in","r",stdin);
     while(input())
     {
         ++cs;
         ) printf("\n");
         memset(used,,sizeof(used));
         printf()?"Possible":"Inpossible");
     }
     ;
 }

Problem:ZOJ P1008

P2672:DP+Hash优化转移

然而谁**能告诉我为啥会TLE!!( >﹏<。)

 #include <cstdio>
 #include <cstring>
 #include <algorithm>

 #include <list>

 struct Hash
 {
     int val;
     int pos;

     Hash(int v,int p):val(v),pos(p) {}
 };

 ;
 ;

 std::list<Hash> hash[dv+];

 typedef std::list<Hash>::iterator Iter;
 Iter x;

 int N;
 int arr[maxN];
 short dp[maxN][maxN];

 inline void insertHash(int v,int p)
 {
     hash[v&dv].push_back(Hash(v,p));
 }

 inline int findHash(int v,int p)
 {
     int res=maxN;
     for(x=hash[v&dv].begin();x!=hash[v&dv].end();++x)
         if(x->val == v && x->pos > p && x->pos < res)
             res=x->pos;
      : res ;
 }

 void init()
 {
     ;i<=dv;i++) hash[i].clear();
     ;i<=N;i++) insertHash(arr[i],i);
 }

 bool input()
 {
     if(scanf("%d",&N)==EOF) return false;
     ;i<=N;i++) scanf("%d",arr+i);
     return true;
 }

 void __solve()
 {
     init();
     ;
     int s,t;

     ;i<N;i++) dp[i][N]=;
     ;j>;j--)
         ;i;i--)
         {
             int f=findHash(arr[j]+arr[i],j);
             ) dp[i][j]=;
             ) > ans)
             {
                 ans=dp[i][j];
                 s=i; t=j;
             }
         }

     printf("%d\n%d %d ",ans,arr[s],arr[t]);
     int f;
     )
     {
         printf("%d ",arr[f]);
         s=t; t=f;
     }
     printf("\n\n");
 }

 void solve()
 {
     ) printf(]);
     ) printf(],arr[]);
     else __solve();
 }

 #include <ctime>

 int main()
 {
     while(input()) solve();
     ;
 }

Problem:ZOJ P2672 TLE

P3300:迷之WA

 #include <cstdio>
 #include <cstring>
 #include <algorithm>

 ];

 bool input()
 {
     int v;
     if(scanf("%d",&v)==EOF) return false;
     memset(cnt,,sizeof(cnt));
     ++cnt[v];
     ;i<=;i++)
     {
         scanf("%d",&v);
         ++cnt[v];
     }
     return true;
 }

 bool dfs(int eye)
 {
     bool res=true;
     ;i<=;i++) if(cnt[i]) { res=false; break; }
     if(res) return true;
     ;i<=;i++)
         ] && cnt[i+])
         {
             --cnt[i]; --cnt[i+]; --cnt[i+];
             res|=dfs(eye);
             if(res) return true;
             ++cnt[i]; ++cnt[i+]; ++cnt[i+];
         }
     ;i<=;i++)
         )
         {
             cnt[i]-=;
             res|=dfs(eye);
             if(res) return true;
             cnt[i]+=;
         }
     if(!eye) {
         ;i<=;i++)
         )
         {
             cnt[i]-=;
             res|=dfs(eye+);
             if(res) return true;
             cnt[i]+=;
         }
     }
     return res;
 }

 void solve()
 {
     ;
     ;i<=;i++)
     {
         ) ++cnt[i];
         else continue;
         ))
         {
             if(ok++) printf(" %d",i);
             else printf("%d",i);
         }
         --cnt[i];
     }
     printf("\n");
 }

 int main()
 {
     while(input()) solve();
     ;
 }

Problem:ZOJ P3300 WA

ZOJ 刷题记录 小黑屋 (`・д・´)的更多相关文章

  1. ZOJ 刷题记录 (。・ω・)ノ゙(Progress:31/50)

    [热烈庆祝ZOJ回归] P1002:简单的DFS #include <cstdio> #include <cstring> #include <algorithm> ...

  2. PE刷题记录

    PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...

  3. leetcode刷题记录--js

    leetcode刷题记录 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但 ...

  4. Leetcode刷题记录(python3)

    Leetcode刷题记录(python3) 顺序刷题 1~5 ---1.两数之和 ---2.两数相加 ---3. 无重复字符的最长子串 ---4.寻找两个有序数组的中位数 ---5.最长回文子串 6- ...

  5. 刷题记录:[HarekazeCTF2019]encode_and_encode

    目录 刷题记录:[HarekazeCTF2019]encode_and_encode 一.知识点 JSON转义字符绕过 php伪协议 刷题记录:[HarekazeCTF2019]encode_and_ ...

  6. 刷题记录:[De1CTF 2019]Giftbox && Comment

    目录 刷题记录:[De1CTF 2019]Giftbox && Comment 一.知识点 1.sql注入 && totp 2.RCE 3.源码泄露 4.敏感文件读取 ...

  7. 刷题记录:[强网杯 2019]Upload

    目录 刷题记录:[强网杯 2019]Upload 一.知识点 1.源码泄露 2.php反序列化 刷题记录:[强网杯 2019]Upload 题目复现链接:https://buuoj.cn/challe ...

  8. 刷题记录:[XNUCA2019Qualifier]EasyPHP

    目录 刷题记录:[XNUCA2019Qualifier]EasyPHP 解法一 1.error_log结合log_errors自定义错误日志 2.include_path设置包含路径 3.php_va ...

  9. 刷题记录:[DDCTF 2019]homebrew event loop

    目录 刷题记录:[DDCTF 2019]homebrew event loop 知识点 1.逻辑漏洞 2.flask session解密 总结 刷题记录:[DDCTF 2019]homebrew ev ...

随机推荐

  1. -_-#【JS】隐含全局变量

    隐含全局变量与明确定义的全局变量有细微的不同,不同之处在于能否使用delete操作符撤销变量 使用var创建的全局变量(这类变量在函数外部创建)不能删除不使用var创建的隐含全局变量(尽管它是在函数内 ...

  2. 数学(概率):HNOI2013 游走

    [题目描述] 一个无向连通图,顶点从1编号到N,边从1编号到M. 小Z在该图上进行随机游走,初始时小Z在1号顶点,每一步小Z以相等的概率随机选 择当前顶点的某条边,沿着这条边走到下一个顶点,获得等于这 ...

  3. codeforces -- 283A

    A. Cows and Sequence time limit per test 3 seconds memory limit per test 256 megabytes input standar ...

  4. Quality in the Test Automation Review Process and Design Review Template

    About this document Prerequisite knowledge/experience: Software Testing, Test Automation Applicable ...

  5. HDOJ 2011 多项式求和

    Problem Description 多项式的描述如下: 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + - 现在请你求出该多项式的前n项的和. Input 输入数据由2行组成, ...

  6. 4种字符串匹配算法:KMP(下)

    回顾:4种字符串匹配算法:BS朴素 Rabin-karp(上) 4种字符串匹配算法:有限自动机(中) 1.图解 KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R ...

  7. java常见错误云集与注意事项

    1.安装Eclipse时,尽量jdk不要用jre,jdk包含jre j JDK就是Java Development Kit.简单的说JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环 ...

  8. SWMM[Storm Water Management Model]模型代码编译调试环境设置

    1. 下载计算引擎源代码后解压, 目前最新版本5-0-022. 其中包含源文件和工程文件,选择vc2005_con.在源代码目录下创建VC2005_CON目录拷贝VC2005-CON.VCPROJ 放 ...

  9. lightoj 1031 区间dp

    题目链接: http://lightoj.com/volume_showproblem.php?problem=1031 #include<cstdio> #include<cstr ...

  10. angularjs post 跨域

    web api搞好了:用Ajax妥妥的:但是前端用的AngulagJS,也懒得再换为Ajax了: 但是问题来了:提示: 已拦截跨源请求:同源策略禁止读取位于 http://x.x.x.x:port/a ...