5510  Bazinga

题意:给出n个字符串,求满足条件的最大下标值或层数

条件:该字符串之前存在不是 它的子串 的字符串

求解si是不是sj的子串,可以用kmp算法之类的。

strstr是黑科技,比手写的kmp快。if(strstr(s[i], s[j]) == NULL),则Si不是Sj的子串。

还有一个重要的剪枝:对于一个串,如果当前找到的串是它的母串,则下一次这个串不用遍历。

 #include <set>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a,int b){return a / gcd(a, b) * b;}

 int T, n;
 ][];
 ];

 int main()
 {
     scanf("%d", &T);
     ; Case <= T; Case++)
     {
         mem(vis, );
         scanf("%d", &n);
         getchar();
         ; i <= n; i++)
         {
             scanf("%s", s[i]);
         }
         ;
         ; i <= n; i++)
         {
             ;
             ; j >= ; j--)
             {
                 if(vis[j]) continue;
                 if(strstr(s[i], s[j]) == NULL)//sj 不是 si的子串
                 {
                     ok = ;
                     break;
                 }
                 else
                 {
                     vis[j] = ;//重要剪枝
                 }
             }
             if(ok) ans = i;
         }
         printf("Case #%d: %d\n", Case, ans);
     }
     ;
 }

5512  Pagodas

题意:有n个庙经过长时间风吹雨打需要修补,只有两座(被标记为a,b)完好无损不需要修补,有两个和尚轮流去修补这n-2个庙,每个和尚每次只能修补一个庙标记为i,并要求i满足i=j+k或者i=j-k,每个庙只能被修建一次;其中j和k代表已经修建好的庙,Yuwgna先开始,问最后谁不能修建谁输;

更相减损术!(gcd里头:辗转相除法,更相减损术,自行百度)

更相减损术:

第一步:任意给定两个正整数;判断它们是否都是偶数。若是,则用2约简;若不是则执行第二步。
第二步:以较大的数减较小的数,接着把所得的差与较小的数比较,并以大数减小数。继续这个操作,直到所得的减数和差相等为止。
则第一步中约掉的若干个2与第二步中等数的乘积就是所求的最大公约数。
所以它在1-n里头,只要是它的最小公因数的倍数的数都是可以选择的点,所以答案是n / gcd(x, y)
主要是由i = j - k联想出来的。
 #include <set>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int T, n, x, y;

 int main()
 {
     scanf("%d", &T);
     ; Case <= T; Case++)
     {
         scanf("%d%d%d", &n, &x, &y);
         int g = gcd(x, y);
         int cnt = n / g;
         printf("Case #%d: ", Case);
         printf( ? "Yuwgna" : "Iaka");
     }
     ;
 }

5521  Meeting

题意:给你一个n个点,m个集合的图,每个集合中的点都可以以di的距离相互的到达,问你两个人同时从1和n出发,会在那个点相遇。

每个集合内部里的所有的边都是互通的,如果一个个连就要n²了,可以采用增加虚拟结点的方式,来减少点。虚拟一个s,一个e,把他们连接起来。

 ; i <= m; i++)
 {
     int w, num;
     int s = n + i, e = n + i + m;
     scanf("%d%d", &w, &num);
  G[s].push_back(edge(e, w));
     while(num--)
     {
         int x;
         scanf("%d", &x);
         G[e].push_back(edge(x, ));
         G[x].push_back(edge(s, ));
     }
 }
 //题意:给你一个n个点,m个集合的图,每个集合中的点都可以以di的距离相互的到达,问你两个人同时从1和n出发,会在那个点相遇。
 #include <set>
 #include <queue>
 #include <cstdio>
 #include <vector>
 #include <cstring>
 #include <algorithm>
 using namespace std;
 typedef long long LL;
 #define mem(x,y) memset(x, y, sizeof(x))
 #define lson l,m,rt << 1
 #define rson m+1,r,rt << 1 | 1
  ? a : gcd(b, a % b);}
 int lcm(int a,int b){return a / gcd(a, b) * b;}

 int T, n, m, Case;
 LL ans;
 ;
 const LL INF = 1e18;

 ;
 LL d1[ssize], d2[ssize];

 struct edge
 {
     int to;
     LL co;
     edge(int tt, LL cc):to(tt), co(cc){}
     bool operator < (const edge &other)const
     {
         return co > other.co;
     }
 };
 vector<edge>G[ssize];
 void init()
 {
     ; i <= n +  * m; i++) G[i].clear();
     ans = INF;
 }
 void dijkstra(int s, LL dis[])
 {
     ; i <= n +  * m; i++) dis[i] = INF;
     priority_queue<edge>que;
     dis[s] = ;
     que.push(edge(s, dis[s]));
     while(!que.empty())
     {
         edge p = que.top();que.pop();
         int v = p.to;
         if(dis[v] < p.co) continue;
         ; i < G[v].size(); i++)
         {
             edge e = G[v][i];
             if(dis[e.to] > dis[v] + e.co)
             {
                 dis[e.to] = dis[v] + e.co;
                 que.push(edge(e.to, dis[e.to]));
             }
         }
     }
 }

 void solve()
 {
     dijkstra(, d1);
     dijkstra(n, d2);
     ans = INF;
     ; i <= n; i++)
     {
         ans = min(ans, max(d1[i], d2[i]));
     }
     printf("Case #%d: ", Case);

     if(ans == INF)
         printf("Evil John\n");
     else
     {
         printf("%I64d\n", ans);
         ;
         ; i <= n; i++)
         {
             if(ans == max(d1[i], d2[i])) cnt++;
         }
         ; i <= n; i++)
         {
             if(ans == max(d1[i], d2[i])) cnt--, printf("%d%c", i, cnt ? ' ' : '\n' );
         }
     }
 }

 int main()
 {
     scanf("%d", &T);
     ; Case <= T; Case++)
     {
         scanf("%d%d", &n, &m);
         init();
         ; i <= m; i++)
         {
             int w, num;
             int s = n + i, e = n + i + m;
             scanf("%d%d", &w, &num);
             G[s].push_back(edge(e, w));
             while(num--)
             {
                 int x;
                 scanf("%d", &x);
                 G[e].push_back(edge(x, ));
                 G[x].push_back(edge(s, ));
             }
         }
         solve();
     }
     ;
 }

2015ACM/ICPC亚洲区沈阳站的更多相关文章

  1. 2015ACM/ICPC亚洲区沈阳站 Pagodas

    Pagodas Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  2. 2015ACM/ICPC亚洲区沈阳站 B-Bazinga

    Bazinga Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  3. hdu 5510 Bazinga (kmp+dfs剪枝) 2015ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

    废话: 这道题很是花了我一番功夫.首先,我不会kmp算法,还专门学了一下这个算法.其次,即使会用kmp,但是如果暴力枚举的话,还是毫无疑问会爆掉.因此在dfs的基础上加上两次剪枝解决了这道题. 题意: ...

  4. 2015ACM/ICPC亚洲区沈阳站 Solution

    A - Pattern String 留坑. B - Bazinga 题意:找一个最大的i,使得前i - 1个字符串中至少不是它的子串 思路:暴力找,如果有一个串已经符合条件,就不用往上更新 #inc ...

  5. 2015ACM/ICPC亚洲区沈阳站 部分题解

    链接在这:http://bak.vjudge.net/contest/132442#overview. A题,给出a,b和n,初始的集合中有a和b,每次都可以从集合中选择不同的两个,相加或者相减,得到 ...

  6. 2015ACM/ICPC亚洲区沈阳站重现赛-HDU5512-Pagodas-gcd

    n pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, l ...

  7. 2015ACM/ICPC亚洲区沈阳站-重现赛 M - Meeting (特殊建边,最短路)

    题意:有\(n\)个点,\(m\)个集合,集合\(E_i\)中的点都与集合中的其它点有一条边权为\(t_i\)的边,现在问第\(1\)个点和第\(n\)个点到某个点的路径最短,输出最短路径和目标点,如 ...

  8. 2015ACM/ICPC亚洲区沈阳站-重现赛 B - Bazinga (KMP)

    题意:给你\(n\)个字符串,\(s_1,s_2,...,s_n\),对于\(i(1\le i\le n)\),找到最大的\(i\),并且满足\(s_j(1\le j<i)\)不是\(s_i\) ...

  9. 2015ACM/ICPC亚洲区沈阳站-重现赛 D - Pagodas

    题意:有\(n\)个数,开始给你两个数\(a\)和\(b\),每次找一个没出现过的数\(i\),要求满足\(i=j+k\)或\(i=j-k\),当某个人没有数可以选的时候判他输,问谁赢. 题解:对于\ ...

随机推荐

  1. 文本框 textarea 动态显示行数(简单文本编辑器)

    工作需求做一个文本编辑器简单的. 右边输入文字,左边会显示相应的代码行.清空也会变为1. 废话不多说上代码,自己理解. <style type="text/css"> ...

  2. <<< java异常The import java.util cannot be resolved

    异常:The import java.util cannot be resolved 原因:这是由于你的项目buildpath不对 解决方案:右键项目-------buildpath--------最 ...

  3. session 和 cookie区别

    1.存在位置cookie是储存在客服端,session是存在服务器端的文件系统/数据库/memcache  2.安全性 session是储存在服务器端,安全性高一些, 3.网络传输量 cookie通过 ...

  4. [Centos 6]升级安装GCC(2)

    摘要 上篇文章升级了下gcc,但发现并没有起到作用. 安装 上篇文章: 升级GCC 升级之后,检查gcc版本 strings /usr/lib/libstdc++.so. | grep GLIBCXX ...

  5. tyvj1098 任务安排

    描述 N个任务排成一个序列在一台机器上等待完成(顺序不得改变),这N个任务被分成若干批,每批包含相邻的若干任务.从时刻0开始,这些任务被分批加工,第i个任务单独完成所需的时间是Ti.在每批任务开始前, ...

  6. [IOS基础]关于IOS的UIScreeen,UIView,UIViewController,UIWindow理解

    UIScreen: 代表当前这个屏幕,通过UIApplication可以获得这个属性 UIView:   一个矩形试图,包含用户手势和时间响应 UIViewController: 一个UIView的集 ...

  7. 修改Linux的SSH远程连接端口 技巧

    将SSH终端服务的端口由 22 修改为别的端口以防攻击黑客直接猜解您的服务器密码 首先修改配置文件 vi /etc/ssh/sshd_config 找到 #Port 22 一段,这里是标识默认使用 2 ...

  8. 如何挂载阿里云Linux服务器的“数据盘”(新购买)

    详细操作参考: http://jingyan.baidu.com/article/90808022d2e9a3fd91c80fe9.html 用到的命令行汇总: 1.查看磁盘: fdisk -l 2. ...

  9. PCA本质和SVD

    一.一些概念 线性相关:其中一个向量可以由其他向量线性表出. 线性无关:其中一个向量不可以由其他向量线性表出,或者另一种说法是找不到一个X不等于0,能够使得AX=0.如果对于一个矩阵A来说它的列是线性 ...

  10. sqlserver中分区函数 partition by的用法

    partition  by关键字是分析性函数的一部分,它和聚合函数(如group by)不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录, partition  by ...