Codeforces731D 80-th Level Archeology
考虑将两个单词变成有序,我们可以得到一个或者两个旋转次数的区间。
然后考虑将两组单词变成有序,比如[l,mid]和[mid+1,r],对于mid和mid+1这两个单词我们可以求出使他们有序的旋转次数的区间。
然后将这个区间与[l,mid]的区间以及[mid+1,r]的区间求交,就可以得到使[l,r]有序的旋转次数的区间。
上面这个过程我们可以用分治来进行,区间求交可以用扫描线法。
- #include <bits/stdc++.h>
- using namespace std;
- vector<int> words[];
- int cnt[];
- int n, c;
- int tot = ;
- void calc(int a, int b)
- {
- int idx = ;
- while (idx < words[a].size() && idx < words[b].size())
- {
- if (words[a][idx] != words[b][idx])
- break;
- idx++;
- }
- if (idx < words[a].size() && idx < words[b].size())
- {
- if (words[a][idx] < words[b][idx])
- {
- cnt[]++;
- cnt[c - words[b][idx] + ]--;
- cnt[c + - words[a][idx]]++;
- cnt[c]--;
- tot++;
- }
- else
- {
- cnt[c + - words[a][idx]]++;
- cnt[c - words[b][idx] + ]--;
- tot++;
- }
- }
- else if (idx == words[a].size() && idx != words[b].size())
- {
- cnt[]++;
- cnt[c]--;
- tot++;
- }
- else if (idx != words[a].size() && idx == words[b].size())
- tot++;
- else
- {
- cnt[]++;
- cnt[c]--;
- tot++;
- }
- }
- void divideConquer(int l, int r)
- {
- if (l == r)
- return;
- int mid = (l + r) >> ;
- divideConquer(l, mid);
- divideConquer(mid + , r);
- calc(mid, mid + );
- }
- int main()
- {
- scanf("%d%d", &n, &c);
- for (int i = ; i < n; i++)
- {
- int l, w;
- scanf("%d", &l);
- while (l--)
- {
- scanf("%d", &w);
- words[i].push_back(w);
- }
- }
- divideConquer(, n - );
- bool ok = false;
- int sum = ;
- for (int i = ; i < c; i++)
- {
- sum += cnt[i];
- if (sum == tot)
- {
- ok = true;
- printf("%d", i);
- break;
- }
- }
- if (!ok)
- printf("-1");
- return ;
- }
Codeforces731D 80-th Level Archeology的更多相关文章
- 80-th Level Archeology
80-th Level Archeology time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #376 (Div. 2) D. 80-th Level Archeology —— 差分法 + 线段扫描法
题目链接:http://codeforces.com/contest/731/problem/D D. 80-th Level Archeology time limit per test 2 sec ...
- CodeForces 731D 80-th Level Archeology
区间并. 对于上下两个数字,如果不一样,那么可以计算出哪一段范围内可以保证字典序,并且后面所有位置都无需再考虑.对所有范围求交集就是答案了. 求交集写起来有点烦,直接对不可取的范围求并即可. #pra ...
- 【codeforces 731D】80-th Level Archeology
[题目链接]:http://codeforces.com/contest/731/problem/D [题意] 给你n个象形文; 每个象形文由l[i]个数字组成; 你可以把所有的组成象形文的数字同时增 ...
- html5-表单
例子: text,number,email 的输入框 <!-- required:必填项 --> <!-- autofocus:获得焦点 --> <!-- placeho ...
- 纯CSS3制作学生入学档案表单样式代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- nc命令总结
1.远程拷贝文件从server1拷贝文件到server2上.需要先在server2上,用nc激活监听,server2上运行: 引用 [root@hatest2 tmp]# nc -l 1234 > ...
- [Canvas]Bombman v1.04
Bombman是我仿造红白机上经典游戏爆破小人,用Canvas制作的一款网页版单机游戏, 自我感觉还是有一定的可玩性. 本游戏的胜利条件是用雷消灭所有怪物,但被怪物即使是擦边碰到或是炸弹火焰炸到就算失 ...
- [Canvas]Bombman v1.00
爆破小人Canvas版,请点此下载,并用浏览器打开试玩. 图例: 源码: <!DOCTYPE html> <html lang="utf-8"> <m ...
随机推荐
- v-if v-else-if v-else
1.代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...
- hdu 2795(单点改动)
题意:有h×w大的公告板.有n条公告要写入,每条公告高度都是1,宽度是wi,每次从最上最左的空位写,假设有空位输出第几行.假设没有足够空位输出-1. 题解:注意h最大1e9.但事实上是看n的大小.由于 ...
- [Pyhton]weakref 弱引用
文档中的解释: https://docs.python.org/2/library/weakref.html wiki 中的解释: 在计算机程序设计中,弱引用.与强引用相对.是指不能确保其引用的对象不 ...
- bash_profile打不开怎么办,用nano .bash_profile打开
I’ve spent years curating a collection of Mac bash aliases and shortcuts to make my life easier. My ...
- C系列语言终极校对宝典【第一、第二部分】
第一部分:基本概念及其它问答题 1.关键字static的作用是什么? 这个简单的问题很少有人能回答完全.在C语言中,关键字static有三个明显的作用: 1). 在函数体,一个被声明为静态的变量在这一 ...
- LeetCode(26)题解:Remove Duplicates from Sorted Array
https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Given a sorted array, remove the ...
- 利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G)
前言: 在项目开发当中,往往需要利用网络.而用户的网络环境也需要我们开发者去注意,根据不同的网络状态作相应的优化,以提升用户体验. 但通常我们只会判断用户是在WIFI还是移动数据,而实际上,移动数据也 ...
- JVM垃圾回收算法 及 垃圾收集器
摘自<深入理解Java虚拟机> 一.什么是: GC算法是 方法论,那么垃圾收集器就是具体的 实现. 二.四种 垃圾回收算法 1.标记-清除算法:最基础的收集算法:不足有两点:1标记和清除两 ...
- 解决ubuntu没有/var/log/messages的问题
1:root身份打开 /etc/rsyslog.d/50-default.conf 2:把注释#去掉 #*.=info;*.=notice;*.=warn;\ # auth,authpriv.none ...
- 编译android内核和文件系统,已经安装jdk,提示build/core/config.mk:268: *** Error: could not find jdk tools.jar
1:确保安装jdk,如果没有安装请移布:http://www.cnblogs.com/jiuyueguang/p/3156621.html 2:如果已经安装了jdk,还是提示此错误, 解决方法 请确保 ...