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 ...
随机推荐
- VS2013带来的"新特性"
VS2013除了引入"Bootstrap"库以外,最大的变化就是.net Framework 4.5下面的都不支持了.也就是说,假设不把.net库升级成.net Framework ...
- Appium启动报Permission Denial的问题
前言 在Android真机上跑自动化脚本时,发现在启动App时报java.lang.SecurityException: Permission Denial: starting Intent : 原先 ...
- Android 通过Application 传递数据
</pre><pre> package com.example.ApplicationTest; import android.app.Application; /** * C ...
- LeetCode题解(19)--Remove Nth Node From End of List
https://leetcode.com/problems/remove-nth-node-from-end-of-list/ 原题: Given a linked list, remove the ...
- UVa 12587 Reduce the Maintenance Cost(Tarjan + 二分 + DFS)
题意:n个城市(n <= 10000), 有m条边(m <= 40000),每一个城市有一个维护费用Cost(i),除此之外,每条边的维修费用为去掉该边后不能通信的城市对数与边权的积.这个 ...
- iptables apache2
Apache2 iptables 安装指令:sudo apt-get install apache2 2.产生的启动和停止文件是:/etc/init.d/apache2 3.启动:sudo apach ...
- URL 下载
package URL; import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import j ...
- 利用WebViewJavascriptBridge与UIWebView进行交互
事情的起因还是因为项目需求驱动.折腾了两天,由于之前没有UIWebView与JS交互的经历,并且觉得这次在功能上有一定的创造性,特此留下一点文字,方便日后回顾. 我要实现这样一个需求:按照本地的CSS ...
- UICollectionView基础用法
初始化部分: UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc]init]; self.myColl ...
- 数据结构之 图论---图的深度遍历( 输出dfs的先后遍历序列 )
图的深度遍历 Time Limit: 1000MS Memory limit: 65536K 题目描述 请定一个无向图,顶点编号从0到n-1,用深度优先搜索(DFS),遍历并输出.遍历时,先遍历节点编 ...