四道比较水的题

T1:SPFA+状压

 #include<stdio.h>
 #include<string.h>
 #include<algorithm>
 #include<queue>
 #define INF 0x3f3f3f3f
 using namespace std;
 ],dis[][],num,N,f[<<][],ans,vis[],mp[][];

 void get_dis(int num){
     queue<,sizeof(vis));
     Q.push(num); dis[num][num]=INF; vis[num]=;
     while (!Q.empty()){
         int now=Q.front(); Q.pop();
         ; i<=n; i++){
             ){
                 dis[num][i]=max(dis[num][i],min(dis[num][now],mp[now][i]));
                 ;
             }
         }
     }
 }

 int main(){
     scanf("%d%d%d", &n, &m, &K);
     ; i<=K; i++) scanf("%d", &id[i]);
     memset(dis,,sizeof(dis));
     ,u,v,w; i<=m; i++) scanf("%d%d%d", &u, &v, &w),mp[v][u]=mp[u][v]=w;
     ; i<=n; i++) get_dis(i);
     N=(<<K);
     ; i<=K; i++) f[<<(i-)][i]=;
     ; s<N; s++){
         num=;
         ; i<=K; i++) <<(i-))) num++;
         ; i<=K; i++) <<(i-))){
             ; j<=K; j++) <<(j-))))
                 <<(j-))][j]|=f[s][i];
         }
         ; i<=K; i++) <<(i-))) && f[s][i]){
             ]);
             ans=max(ans,t);
         }
     }
     printf("%d\n", ans);
     ;
 }

T2:裸RMQ

 #include<stdio.h>
 #include<string.h>
 #include<algorithm>
 #include<cmath>
 using namespace std;
 ;
 ];
 int main(){
     scanf("%d%d", &n, &m);
     ; i<=n; i++) scanf(]);
     ; (<<j)<=n; j++)
         ; i+(<<(j-))<=n; i++)
             f[i][j]=min(f[i][j-],f[i+(<<(j-))][j-]);
     ,a,b; i<=m; i++){
         scanf("%d%d", &a, &b);
         )/log();
         printf(<<t)+][t]));
     }
     ;
 }

T3:曼哈顿距离转切比雪夫距离

 #include<stdio.h>
 #include<algorithm>
 #include<string.h>
 #define INF 1000010
 using namespace std;
 int n,a,b,x,y,mxx,mxy,mnx,mny;
 int main(){
     scanf("%d", &n);
     mxx=mxy=-INF; mnx=mny=INF;
     ; i<=n; i++){
         scanf("%d%d", &a, &b);
         x=b+a; y=b-a;
         mnx=min(mnx,x); mxx=max(mxx,x);
         mny=min(mny,y); mxy=max(mxy,y);
     }
     printf("%d\n", max(mxx-mnx,mxy-mny));
     ;
 }

T4:set+最短路

 #include<stdio.h>
 #include<string.h>
 #include<queue>
 #include<set>
 #include<algorithm>
 using namespace std;
 ;
 struct node{
     int x,y,id;
     friend bool operator<(node a, node b){
         if (a.x==b.x) return a.y<b.y;
         return a.x<b.x;
     }
 };
 int n,t,x[maxn],y[maxn],dis[maxn];
 queue<int> Q;
 set<node> st;
 node mk(int x, int y, int id){
     node a; a.x=x; a.y=y; a.id=id; return a;
 }
 int main(){
     scanf("%d%d", &n, &t);
     ; i<=n; i++){
         scanf("%d%d", &x[i], &y[i]);
         st.insert(mk(x[i],y[i],i));
     }
     dis[]=; x[]=y[]=;
     Q.push();
     while (!Q.empty()){
         int now=Q.front(); Q.pop();
         ; i<=; i++) ; j<=; j++){
             int X=x[now]+i, Y=y[now]+j;
             ));
             if (next!=st.end()){
                 dis[next->id]=dis[now]+;
                 Q.push(next->id);
                 if (Y>=t){
                     printf("%d\n", dis[next->id]);
                     ;
                 }
                 st.erase(next);
             }
         }
     }
     puts("-1");
     ;
 }

bzoj3380+3381+3382+3383 Usaco2004 Open的更多相关文章

  1. Hsql中In没有1000的限制

    SELECT * FROM user , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  2. 基于json的jquery地区联动探索

    贴一个基于jquery联动的代码,相信这样的代码有一大把,就当是jquery的练手吧, 写这个东西的初衷是来之于新浪微博,在新浪微博帐号设置里面有个地区的选项,使用js写的,想把它的代码给截获下来,可 ...

  3. JS逆向-抠代码的第二天【手把手学会抠代码】

    今天的学习项目:沃支付:https://epay.10010.com/auth/login 清空浏览器缓存后,打开网页,输入手机号,密码222222,按照网站要求填入验证码(sorry,我没有账号密码 ...

  4. 游戏中的自动寻路-A*算法(第一版优化——走斜线篇)

    一.简述以及地图 G 表示从起点移动到网格上指定方格的移动距离 (暂时不考虑沿斜向移动,只考虑上下左右移动). H 表示从指定的方格移动到终点的预计移动距离,只计算直线距离,走直角篇走的是直角路线. ...

  5. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  6. jqu

    1 /*2 * 说明:3 * 本源代码的中文注释乃Auscarlin呕心沥血所作.旨在促进jQuery的传播以及向广大jQuery爱好者提供一个进阶4 *的途径,以让各位更加深入地了解jQuery,学 ...

  7. 3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二

    3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 21  Solved ...

  8. bzoj3380: [Usaco2004 Open]Cave Cows 1 洞穴里的牛之一(spfa+状压DP)

    数据最多14个有宝藏的地方,所以可以想到用状压dp 可以先预处理出每个i到j的路径中最小权值的最大值dis[i][j] 本来想用Floyd写,无奈太弱调不出来..后来改用spfa 然后进行dp,这基本 ...

  9. [BZOJ3380] [USACO2004 Open]Cave Cows 1 洞穴里的牛之一

    Description ​ 很少人知道其实奶牛非常喜欢到洞穴里面去探险. ​ 洞窟里有N(1≤N≤100)个洞室,由M(1≤M≤1000)条双向通道连接着它们.每对洞室间 至多只有一条双向通道.有K( ...

随机推荐

  1. TCP/IP协议三次握手与四次握手流程解析

    原文链接地址:http://www.2cto.com/net/201310/251896.html TCP/IP协议三次握手与四次握手流程解析 TCP/IP协议的详细信息参看<TCP/IP协议详 ...

  2. 51nod1459(带权值的dijkstra)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1459 题意:中文题诶- 思路:带权值的最短路,这道题数据也没 ...

  3. IntelliJ Idea 常用快捷键 列表

    1. -----------自动代码-------- 常用的有fori/sout/psvm+Tab即可生成循环.System.out.main方法等boilerplate样板代码 例如要输入for(U ...

  4. linux内核(kernel)版本号的意义

    转自:http://www.cnblogs.com/jsjliuxing/archive/2011/12/01/2271182.html 在linux下有一个目录,即/usr/src/kernels/ ...

  5. jsp include flush true

    设置flush为true,就是说,如果你的缓冲区的内容很多了,就将数据读出,以免数据泄漏,造成错误服务器端页面缓冲,大致的意思是,在将生成的HTML代码送到客户端前,先在服务器端内存中保留,因为解释J ...

  6. Good Bye 2016 - B

    题目链接:http://codeforces.com/contest/750/problem/B 题意:地球的子午线长度为40000,两极点的距离为20000.现在你从北极出发,按照题目输入方式来走. ...

  7. 在php中使用strace、gdb、tcpdump调试工具

    [转] http://www.syyong.com/php/Using-strace-GDB-and-tcpdump-debugging-tools-in-PHP.html 在php中我们最常使用调试 ...

  8. oracle(sql)基础篇系列(五)——PLSQL、游标、存储过程、触发器

      PL/SQL PL/SQL 简介 每一种数据库都有这样的一种语言,PL/SQL 是在Oracle里面的一种编程语言,在Oracle内部使用的编程语言.我们知道SQL语言是没有分支和循环的,而PL语 ...

  9. Server.MapPath()

    ./当前目录/网站主目录../上层目录~/网站虚拟目录 如果当前的网站目录为E:\wwwroot   应用程序虚拟目录为E:\wwwroot\company 浏览的页面路径为E:\wwwroot\co ...

  10. JQUERY UI Datepicker Demo

    datepicker_demo.htm <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" &quo ...