【codeforces 731D】80-th Level Archeology
【题目链接】:http://codeforces.com/contest/731/problem/D
【题意】
给你n个象形文;
每个象形文由l[i]个数字组成;
你可以把所有的组成象形文的数字同时增加1;
超过c的变成1;
然后让你用这个操作使得n个象形文按照字典序升序
排;
问你最小的操作次数;
【题解】
首先;
得先让这n个字符串,相邻的两个的字符串都符合字典序
即s[i]<=s[i+1];
所以;
可以分别处理出使得这n-1个相邻的关系成立的操作步数;
只考虑第一个不同的位置就好;
因为前面不管怎么改变都是一样的;
比如n-1个相邻关系种的
s[3]和s[4]
如果
s[3][i]和s[4][i]是第一个不同的位置;
②
则如果s[3][i]< s[4][i]
那么0..c-s4[i]和c-s[3][i]+1..c这个两个区间内的数对应的操作次数;
都能使s[3][i]< s[4][i]成立;
②
如果s[3][i]>s[4][i]
则c-s[3][i]+1..c-s[4][i]这个区间范围内的数对应的操作次数,都能使得s[3][i]< s[4][i]成立;
求这n-1个区间的交就好;
如果有一个区间能够使得这n-1个关系都满足则输出最小的就好;
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 5e5+100;
const int M = 1e6+100;
int n,c,l[N],sum[M],sum1[M];
vector <int> G[N];
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
//init??????
cin >> n >> c;
rep1(i,1,n)
{
cin >> l[i];
int x;
rep1(j,1,l[i])
{
cin >> x;
G[i].pb(x);
}
}
rep1(i,1,n-1)
{
int len = min(l[i],l[i+1]);
int j;
for ( j = 0;j <= len-1;j++)
if (G[i][j]!=G[i+1][j])
break;
if (j==len)
{
if (l[i]>l[i+1])
return cout <<-1<<endl,0;
sum[0]++;
continue;
}
if (G[i][j]<G[i+1][j])
{
sum[0]++;
//s[i][j]<s[i+1][j]
sum[c-G[i+1][j]+1]--;
sum[c-G[i][j]+1]++;
}
else
{
//s[i][j]>s[i+1][j]
sum[c-G[i][j]+1]++;
sum[c-G[i+1][j]+1]--;
}
}
rep1(i,1,c) sum[i] += sum[i-1];
rep1(i,0,c)
if (sum[i]==n-1)
{
cout <<i<<endl;
return 0;
}
cout <<-1<<endl;
return 0;
}
【codeforces 731D】80-th Level Archeology的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【13.77%】【codeforces 734C】Anton and Making Potions
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【51.27%】【codeforces 604A】Uncowed Forces
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- 【33.33%】【codeforces 608C】Chain Reaction
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- oracle 数据库中数据导出到excel
确保安装了PLSQL Developer工具.连接数据库. FIle--new--SQL window 运行查询,选中要导出的数据,右键--copy to excel. 或者 运行查询后.右键--se ...
- 11gR2 Database Services for "Policy" and "Administrator" Managed Databases (文档 ID 1481647.1)
In this Document Purpose _afrLoop=1459311711568804&id=1481647.1&displayIndex=6&_afrW ...
- HDU4300-Clairewd’s message-KMP
题目链接:pid=4300">http://acm.hdu.edu.cn/showproblem.php?pid=4300 题目意思真的非常难读懂. 题意:给定两组字符串,第一组仅仅有 ...
- [转]详细解读TrueSkill 排名系统
概要 大多数竞技游戏都有一个评价玩家是否完成目标的度量指标,它是游戏的基础.对于包含两个或两个以上玩家(多玩家比赛)的比赛,常涉及到游戏玩家技能的排名方法.游戏鼓励玩家之间相互竞争,玩家不只要赢得单场 ...
- Spark中常用的算法
Spark中常用的算法: 3.2.1 分类算法 分类算法属于监督式学习,使用类标签已知的样本建立一个分类函数或分类模型,应用分类模型,能把数据库中的类标签未知的数据进行归类.分类在数据挖掘中是一项重要 ...
- Node.js:常用工具
ylbtech-Node.js:常用工具 1.返回顶部 1. Node.js 常用工具 util 是一个Node.js 核心模块,提供常用函数的集合,用于弥补核心JavaScript 的功能 过于精简 ...
- python print 显示不同的字体
显示格式: print('\033[显示方式;字体颜色;背景色m.....\033[0m') ------------------------------- 显示方式 | 效果 ----------- ...
- Kafka .NET操作
Kafaka .NET连接 Kafka目前主流在用的.NET客户端有两个:一个是kafka-net,另外一个是Confluent.Kafka,这里给出使用示例: kafka-net示例: public ...
- springmvc-servlet.xml(springmvc-servlet.xml 配置 增强配置)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- guice整合struts2与jpa,guice的使用(九)
传统我们开发一般使用ssh,但是有些微服务应用的项目我们不需要这么臃肿的框架做开发,于是采用了guice+struts2+guice作为框架组合进行了开发. 先看我们项目引用的jar包: 使用的时候一 ...