https://www.hackerrank.com/contests/101hack45/challenges/the-chosen-one

找出一个数字,使得,数组中只有一个数字不是这个数的约数,而且其他数都是这个数的约数。

如果暴力枚举每一个i,表示,就是要排除这个数字,那么,需要找到一个数能被剩下的数都整除。那么最优解就是gcd了。

因为他们的gcd,就是最大公约数,被排除的那个数字最不可能整除这个数。

所以快速求剩下数字的gcd就需要预处理pre[i]表示前i个数的gcd,last[i]表示i--n的gcd,然后再gcd

注意特判n = =

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e5 + ;
LL pre[maxn];
LL last[maxn];
LL a[maxn];
void work() {
int n;
scanf("%d", &n);
for (int i = ; i <= n; ++i) {
cin >> a[i];
}
pre[] = ;
pre[] = a[];
for (int i = ; i <= n; ++i) {
pre[i] = __gcd(pre[i - ], a[i]);
}
last[n + ] = ;
last[n] = a[n];
for (int i = n - ; i >= ; --i) {
last[i] = __gcd(last[i + ], a[i]);
}
for (int i = ; i <= n; ++i) {
LL t;
if (i == ) {
t = last[i + ];
} else if (i == n) {
t = pre[i - ];
} else t = __gcd(pre[i - ], last[i + ]);
if (a[i] % t != ) {
cout << t << endl;
return;
}
}
cout << a[n] + << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

The Chosen One的更多相关文章

  1. jQuery下拉框扩展和美化插件Chosen

    Chosen 是一个支持jquery的select下拉框美化插件,它能让丑陋的.很长的select选择框变的更好看.更方便.不仅如此,它更扩展了select,增加了自动筛选的功能.它可对列表进行分组, ...

  2. chosen组件实现下拉框

    chosen组件用于增强原生的select控件,使之有更好的用户体验.官方demo https://harvesthq.github.io/chosen/ 目前项目中碰到的使用,比如一个页面中有两个不 ...

  3. android xml 布局错误(黑掉了)Missing styles. Is the correct theme chosen for this layout?

    发现在调整页面的时候 ,老是报以下错误,导致无法静态显示ui效果. Missing styles. Is the correct theme chosen for this layout? Use t ...

  4. chosen PersistenceUnitInfo does not specify a provider class name

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceI ...

  5. 带搜索框的下拉框chosen.jQury.js

    下载所需js,css png资源     <link href="chosen.css" rel="stylesheet" type="text ...

  6. jquery.chosen.js实现模糊搜索

    jquery.chosen.js查询时,chosen默认从第一个字符搜索,所以写中间的字符搜索时,是搜索不出来的 若想实现中间字符的模糊查询,下面的js中(search_contains属性为true ...

  7. jquery plugins —— Chosen

    官网地址:http://harvesthq.github.io/chosen/ Chosen (v1.4.2) Chosen has a number of options and attribute ...

  8. Chosen中选择项的更新

    Chosen 选择项的动态修改/更新 如果你需要去动态更新select选择框里的选择项,你需要通知Chosen去响应这个变动,你需要在这个选项框是触发一个"liszt:updated&quo ...

  9. 带搜索的下拉框Chosen

    一:参考 https://harvesthq.github.io/chosen/ Chosen是一个jQuery插件 二:引入js文件 <link href="plug-in/chos ...

  10. chosen 下拉框

    $("#teams").trigger("liszt:updated");//更新重新绑定                            $(" ...

随机推荐

  1. 封装java-get-post请求方式

    package com.ecar.eoc.content.platform.utils; import java.io.IOException;import java.util.HashMap;imp ...

  2. maven的安装与环境变量配置

    1.下载maven 地址:http://maven.apache.org/download.cgi 点击下载 apache-maven-3.2.1-bin.zip. 2.安装配置,假设maven 解压 ...

  3. 【Unix编程】C/C++获取目录下文件或目录

    在Unix/Linux系统中,要获取一个指定目录下所有的文件或文件夹,一般用dirent.h(POSIX标准定义的目录操作头文件). 一.数据类型 在头文件<dirent.h>中定义了两种 ...

  4. Mariadb 索引及外键

    索引 索引相当于一本书的目录,在一个数据库或表有索引的情况下,会很便于查询数据,使查询更加效率,相对的也有缺点,不利于去修改,比较麻烦,有索引便于查询,那就意味着索引创建的越多越好么?然而并不是:索引 ...

  5. ASP.NET Boilerplate 学习 AspNet Core2 浏览器缓存使用 c#基础,单线程,跨线程访问和线程带参数 wpf 禁用启用webbroswer右键菜单 EF Core 2.0使用MsSql/MySql实现DB First和Code First ASP.NET Core部署到Windows IIS QRCode.js:使用 JavaScript 生成

    ASP.NET Boilerplate 学习   1.在http://www.aspnetboilerplate.com/Templates 网站下载ABP模版 2.解压后打开解决方案,解决方案目录: ...

  6. centOS的联网问题

    centOS连接了一个下午,没连上网络,隔了两天,又试了一下午才把网连上,一直查centOS的网络连接问题都搞不定,最后还是问了朋友怎么给虚拟机联网谈到虚拟网卡的问题.建议可以看看网络适配器,VMwa ...

  7. Python爬虫开发【第1篇】【beautifulSoup4解析器】

    CSS 选择器:BeautifulSoup4 Beautiful Soup 也是一个HTML/XML的解析器,主要的功能也是如何解析和提取 HTML/XML 数据. pip 安装:pip instal ...

  8. 利用runtime检測这个对象是否存在某属性?

    假定有实例对象-instance,我们怎样知道该实例对象是否存在属性-propertyName? 利用runtime,我们能够获取到它的属性列表 1)属性列表 unsigned int outCoun ...

  9. extern &quot;C&quot; 的含义:实现C++与C及其他语言的混合编程

    C++中extern "C"的设立动机是实现C++与C及其他语言的混合编程.        C++为了支持函数的重载,C++对全局函数的处理方式与C有明显的不同.对于函数void ...

  10. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] B. Finding Team Member 排序

                                                                      B. Finding Team Member             ...