CodeForces 359D Pair of Numbers (暴力)
题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素。
析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为r。那么我们下一点考虑r+1即可,
因为[l, r]之间不会有更优解。
代码如下:
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- #include <iostream>
- #include <cstring>
- #include <set>
- #include <queue>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <cctype>
- #include <cmath>
- #include <stack>
- #include <sstream>
- #define debug() puts("++++");
- #define gcd(a, b) __gcd(a, b)
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define freopenr freopen("in.txt", "r", stdin)
- #define freopenw freopen("out.txt", "w", stdout)
- using namespace std;
- typedef long long LL;
- typedef unsigned long long ULL;
- typedef pair<double, int> P;
- const int INF = 0x3f3f3f3f;
- const double inf = 0x3f3f3f3f3f3f;
- const double PI = acos(-1.0);
- const double eps = 1e-5;
- const int maxn = 3e5 + 10;
- const int mod = 1e6;
- const int dr[] = {-1, 0, 1, 0};
- const int dc[] = {0, 1, 0, -1};
- const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
- int n, m;
- const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- inline bool is_in(int r, int c){
- return r >= 0 && r < n && c >= 0 && c < m;
- }
- int a[maxn];
- int main(){
- scanf("%d", &n);
- for(int i = 1; i <= n; ++i) scanf("%d", a+i);
- int r = 0;
- int ans = 0;
- vector<int> v;
- for(int i = 1; i <= n; i = r){
- if(a[i] == 1){
- printf("1 %d\n1\n", n-1);
- return 0;
- }
- int l = i; r = i;
- while(a[l] % a[i] == 0 && l > 0) --l;
- while(r <= n && a[r] % a[i] == 0) ++r;
- if(ans < r-l-2){
- ans = r-l-2; v.clear();
- }
- if(ans == r-l-2) v.push_back(l+1);
- }
- printf("%d %d\n", v.size(), ans);
- for(int i = 0; i < v.size(); ++i){
- if(i) putchar(' ');
- printf("%d", v[i]);
- }
- printf("\n");
- return 0;
- }
CodeForces 359D Pair of Numbers (暴力)的更多相关文章
- [codeforces] 359D Pair of Numbers
原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和g ...
- Codeforces 359D Pair of Numbers | 二分+ST表+gcd
题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...
- Codeforces 395 D.Pair of Numbers
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #209 (Div. 2) D. Pair of Numbers (模拟)
D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- CodeForces 359D (数论+二分+ST算法)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...
- cf359D Pair of Numbers
Simon has an array a1, a2, ..., an, consisting of n positive integers. Today Simon asked you to find ...
- Educational Codeforces Round 23 C. Really Big Numbers 暴力
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- codeforces 9 div2 C.Hexadecimal's Numbers 暴力打表
C. Hexadecimal's Numbers time limit per test 1 second memory limit per test 64 megabytes input stand ...
随机推荐
- node JS 微信开发
JS-SDK 要点 微信测试号; 扫码登录;无需认证(只是名称统一为微信测试号)http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/logi ...
- 改动UITextfield的Placeholder字体的颜色
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- JAVA with Cassandra
maven项目,在pom.xml里加入依赖.不是的话下载相应的jar包放到lib目录下.这里驱动包的版本要和你cassandra的大版本一致. <dependency> <group ...
- Android笔记之dp与px之间的转换以及LayoutParams
dp与px之间的转换公式 px = dp * (dpi / 160) dp = px / (dpi / 160) 其中dpi的获取方式如下 private void getDpi() { Displa ...
- 20170313 ABAP以jason 格式返回值到http(接口内容返回)
问题1: 返回jason 格式信息给你们这步不通, 这个可以怎么处理, ***得到SCP 系统开发回复,他们需要调整方法: (1)调用函数做RETURN, IT_ZSMLSCPNOTICE-FUNC ...
- R in Action(1) 基本数据结构
一数据类型 R的数据类型包括数值型.字符型.逻辑型(布尔).复数型和原生型,同时R有好多存储数据的对象类型,包括标量.向量.矩阵.数组.数据框和列表,如下图所示下图(图的版权神马的归原作者跟原出版社所 ...
- CRM 安装不规范,亲人两行泪
安装CRM需要严格按照CRM部署文档的要求进行,比如设置CRM服务的服务账号一定要加入到CRM所在组织库用户里,不然会遇到下面错误.这个就是传递到SQL 的账号,在SQL那边不识别 <s:Env ...
- 人生苦短之Python枚举类型enum
枚举类型enum是比较重要的一个数据类型,它是一种数据类型而不是数据结构,我们通常将一组常用的常数声明成枚举类型方便后续的使用.当一个变量有几种可能的取值的时候,我们将它定义为枚举类型.在Python ...
- RobotFramework教程使用笔记——时间控件的相关操作
在web测试过程中,我们可能会遇到时间控件,有的是支持直接输入的,有的为了保证输入时间格式的一致性是只支持点击选择的,那么这个时候如何用robotframework来操作呢? 看下面这个例子: 这个是 ...
- 网站流量统计之PV和UV
转自:http://blog.csdn.NET/webdesman/article/details/4062069 如果您是一个站长,或是一个SEO,您一定对于网站统计系统不会陌生,对于SEO新手来说 ...