四道比较水的题

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. 第三天--html表格

    <!Doctype html><html>    <head>        <meta charset="UTF-8">      ...

  2. Windows Server 2008 R2 IIS7.5 部署 MVC HTTP 404.0 Not Found 错误

    如图 在Windows Server 2008 R2 IIS7.5 部署 MVC HTTP 404.0 Not Found 错误,在Win7环境下测试正常,在百度中查找相关解决方法,如修改配置文件等, ...

  3. iOS - 如何切图适配各种机型

    关于iPhone6/6+适配问题一直有争议,今天小编专门为大家整理了相关的有效方案,希望对大伙儿有帮助! 移动app开发中多种设备尺寸适配问题,过去只属于Android阵营的头疼事儿,只是很多设计师选 ...

  4. ajaxform使用

    需要引入  jquery.form.js  jquery.js 1.提交的表单 <form id="myForm" action="comment.php" ...

  5. Blender 脚本之 Operator 初探

    addon(插件)用来扩展 Blender 的功能,跟其他软件里的 plugin(插件)一样,去掉不会影响软件的运行.插件可以加到 Blender 的用户偏好设置目录里,或者就在你所编辑的.blend ...

  6. 2017年第1贴:EXT.JS使用MVC模式时,注意如何协调MODEL, STORE,VIEW,CONTROLLER的关系

    也调了快一天,死活找不到窍门. MODEL, STORE,VIEW的调置测试了很久,试了N种方法,不得其果. 最后,试着在APPLICATION里加入CONTROLLER, 在CONTROLLER里加 ...

  7. 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)

    湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...

  8. python学习 2数学公式

    递归 def fact(n): if n <= 1: return 1 else: return n * fact(n - 1) 斐波那契数列: 第0项是0,第1项是1,从第2项开始,每一项都等 ...

  9. POJ 2774 Long Long Message ——后缀数组

    [题目分析] 用height数组RMQ的性质去求最长的公共子串. 要求sa[i]和sa[i-1]必须在两个串中,然后取height的MAX. 利用中间的字符来连接两个字符串的思想很巧妙,记得最后还需要 ...

  10. Asp.net mvc页面传值-- dropdownlist

    后台传值 List<ConfigParamInfo> paramList = configParamBLL.GetModelList(" and parentID=1" ...