「PKUSC2018」星际穿越 (70分做法)
5371: [Pkusc2018]星际穿越
Time Limit: 10 Sec Memory Limit: 512 MB
Submit: 27 Solved: 11
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 1 2 1 4 6
5
3 4 6
1 5 7
1 2 4
1 2 6
1 3 5
Sample Output
13/5
3/2
2/1
1/1
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- const int maxn=5005;
- int mn[maxn],L[maxn],n,Q,f[maxn][maxn],d[maxn][maxn],a,b,c;
- int gcd(int x,int y){ return y?gcd(y,x%y):x;}
- inline void prework(){
- mn[n+1]=n+1;
- for(int i=n;i;i--) mn[i]=min(mn[i+1],L[i]);
- for(int i=1;i<=n;i++) f[i][2]=mn[i+1],f[i][0]=i,f[i][1]=L[i];
- for(int i=2,k,j;i<=n;i++){
- k=i-1;
- for(j=1;f[i][j]>1;j++)
- for(;k>=f[i][j];k--) f[i][j+1]=min(f[i][j+1],L[k]),d[i][k]=j;
- for(;k;k--) d[i][k]=j;
- }
- for(int i=2;i<=n;i++)
- for(int j=1;j<i;j++) d[i][j]+=d[i][j-1];
- }
- inline void solve(){
- scanf("%d",&Q);
- while(Q--){
- scanf("%d%d%d",&a,&b,&c);
- c=d[c][b]-d[c][a-1];
- a=b-a+1,b=gcd(a,c);
- a/=b,c/=b;
- printf("%d/%d\n",c,a);
- }
- }
- int main(){
- memset(f,0x3f,sizeof(f));
- scanf("%d",&n),L[1]=1;
- for(int i=2;i<=n;i++) scanf("%d",L+i);
- prework();
- solve();
- return 0;
- }
「PKUSC2018」星际穿越 (70分做法)的更多相关文章
- LOJ #6435. 「PKUSC2018」星际穿越(倍增)
题面 LOJ#6435. 「PKUSC2018」星际穿越 题解 参考了 这位大佬的博客 这道题好恶心啊qwq~~ 首先一定要认真阅读题目 !! 注意 \(l_i<r_i<x_i\) 这个条 ...
- 【LOJ】#6435. 「PKUSC2018」星际穿越
题解 想出70的大众分之后就弃疗了,正解有点神仙 就是首先有个比较显然的结论,就是要么是一直往左走,要么是走一步右边,然后一直往左走 根据这个可以结合RMQ写个70分的暴力 我们就考虑,最优的话显然是 ...
- #6435. 「PKUSC2018」星际穿越
考场上写出了70分,现在填个坑 比较好写的70分是这样的:(我考场上写的贼复杂) 设\(L(i)=\min_{j=i}^nl(j)\) 那么从i开始向左走第一步能到达的就是\([l(i),i-1]\) ...
- LOJ 6435 「PKUSC2018」星际穿越——DP+倍增 / 思路+主席树
题目:https://loj.ac/problem/6435 题解:https://www.cnblogs.com/HocRiser/p/9166459.html 自己要怎样才能想到怎么做呢…… dp ...
- 「PKUSC2018」星际穿越(倍增)
倍增好题啊! 我们我们预处理 \(f[x][i]\) 表示 \(x\) 点最左到达的端点,\(sum[x][i]\) 表示 \(x\) 点最左到达的端点时 \(f[x][i]\sim x\) 的答案, ...
- loj#6435. 「PKUSC2018」星际穿越(倍增)
题面 传送门 题解 我们先想想,在这个很特殊的图里该怎么走最短路 先设几个量,\(a_i\)表示\([a_i,i-1]\)之间的点都和\(i\)有边(即题中的\(l_i\)),\(l\)表示当前在计算 ...
- 「PKUSC2018」星际穿越
传送门 Solution 倍增 Code #include <bits/stdc++.h> #define reg register #define ll long long usin ...
- LOJ #6436. 「PKUSC2018」神仙的游戏(字符串+NTT)
题面 LOJ #6436. 「PKUSC2018」神仙的游戏 题解 参考 yyb 的口中的长郡最强选手 租酥雨大佬的博客 ... 一开始以为 通配符匹配 就是类似于 BZOJ 4259: 残缺的字符串 ...
- LOJ #6432. 「PKUSC2018」真实排名(组合数)
题面 LOJ #6432. 「PKUSC2018」真实排名 注意排名的定义 , 分数不小于他的选手数量 !!! 题解 有点坑的细节题 ... 思路很简单 , 把每个数分两种情况讨论一下了 . 假设它为 ...
随机推荐
- Spring的使用优点
spring事物配置,声明式事务管理和基于@Transactional注解的使用 spring支持编程式事务管理和声明式事务管理两种方式. 编程式事务管理使用TransactionTemplate或者 ...
- elementui table 多选 获取id
//多选相关方法 toggleSelection(rows) { if (rows) { rows.forEach(row => { this.$refs.multipleTable.toggl ...
- C#编写程序监测某个文件夹内是否有文件进行了增,删,改的动作?
新建一个Console应用程序,项目名称为“FileSystemWatcher”,Copy代码进,编译后就可以用了.代码如下: using System; using System.Collectio ...
- 【Windows使用笔记】Windows科研软件
1 Anaconda Anaconda指的是一个开源的Python发行版本,其包含了conda.Python等180多个科学包及其依赖项.主要是内置有jupyter notebook和jupyter ...
- 64_c1
CBFlib-0.9.5.15-3.fc26.i686.rpm 05-Feb-2017 21:55 427710 CBFlib-0.9.5.15-3.fc26.x86_64.rpm 05-Feb-20 ...
- idea+spring+springmvc+mybatis+mybatis+maven
使用SSM(Spring,SpringMVC和Mybatis) 1.1.Spring Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johns ...
- javascript方法--call()
关于call方法,以前经常看到这个方法,但是也没怎么用心去学习,后来觉得不行,所以知识在一点一点补~ 今天对自己学习call方法做一下总结 其实,学了call方法,会发现call跟apply其实是很像 ...
- ASP.NET Core学习链接
https://www.cnblogs.com/artech/p/dependency-injection-in-asp-net-core.html http://www.cnblogs.com/ar ...
- LeetCode解题报告—— Reverse Nodes in k-Group && Sudoku Solver
1. Reverse Nodes in k-Group Given a linked list, reverse the nodes of a linked list k at a time and ...
- Word Search——经典题(还没细看)
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...