CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes!) A ~ D
A.
给定一个序列,对于任意1<=k<=n 都满足|ai−ak|+|ak−aj|=|ai−aj|,
找满足条件的i和j并输出
思路:
观察样例,发现输出的是最大值和最小值,那么猜答案是最大值和最小值,进行证明
若答案不是最大值和最小值,则一定存在一个k使得|ak-ap|大于|aj-ai| 一定不满足|ai−ak|+|ak−aj|=|ai−aj| 与命题矛盾
所以记录最大值和最小值 输出即可。
代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
#define int long long
#define debug(x) cout << "*" << x << endl;
const int P = 13131;
#define ll long long
const int mod = 1E6 + 7;
const int INF = 0x3f, sINF = 0x3f3f3f3f;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 3e5 + 10;;
int T;
const int UN = 1e9 + 10; signed main()
{
cin>>T;
while(T--)
{
int n;
int maxa = 0, mina = UN;
cin>>n;
int ans1, ans2;
for(int i = 1; i <= n; i++)
{
int temp;
cin>>temp; if(temp > maxa)
{
ans1 = i;
maxa = temp;
} if(temp < mina)
{
ans2 = i;
mina = temp;
}
}
if(n == 1) cout<<"1 1"<<endl;
else cout<<ans2<<" "<<ans1<<endl; }
}
B
给定一个序列,每次去除任意一个元素,并且将其他剩余元素都减去这个元素的值,给定一个k,能否让最后剩下的那个数为k
思路:
推公式,模拟一下a1,a2 和 a1,a2,a3情况,并且以总和的角度来看,发现所有的答案都只与两个元素之间的差的绝对值有关
a1,a2,a3情况: 总和为a1+a2+a3
假如去除的是a2 那么总和就为(a1 - a2) + (a3 - a2),剩两个元素的时候求得就是他俩的差的绝对值了,那么就是|a1 - a2 - a3 + a2| = |a1 - a3|
去除的是其他同理,发现多个元素的时候都可以消成这种形式。那么答案就是在任意两个元素的差的绝对值之中,哈希表判断是否存在即可。
代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
#define int long long
#define debug(x) cout << "*" << x << endl;
const int P = 13131;
#define ll long long
const int mod = 1E6 + 7;
const int INF = 0x3f, sINF = 0x3f3f3f3f;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 2e5 + 10;;
int T;
const int UN = 1e9 + 10;
int q[N]; signed main()
{
cin>>T;
while(T--)
{
map<int, bool> s;
int n, k;
cin>>n>>k;
for(int i = 0; i < n; i++)
{
cin>>q[i];
s[q[i]] = true; //出现过这个
} bool isk = false;
for(int i = 0; i < n; i++)
if(s[q[i] - k] || s[q[i] + k])
{
isk = true;
break;
} if(isk) puts("YES");
else puts("NO");
}
}
C
给定一个序列,可以选择任意k>=2 对里面所有元素模k 有没有可能让所有元素相等。
思路:仔细想想即可发现,只要从大到小模,一定可以把所有元素模为0或者1,那么问题仅存在于0,1之间。
1怎么也到不了0 ,所以一旦0,1都出现,就一定NO。如果没0,只有1,那所有元素必须化为1,但对于p %= p-1,如果存在另一个p-1的元素,那么一定会出现0
所以此时不能存在差值为1的元素对。
其他所有情况都输出YES,只要按照从大到小模
代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
#define int long long
#define debug(x) cout << "*" << x << endl;
const int P = 13131;
#define ll long long
const int mod = 1E6 + 7;
const int INF = 0x3f, sINF = 0x3f3f3f3f;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1e5 + 10;;
int T;
const int UN = 1e9 + 10;
int q[N]; signed main()
{
cin>>T;
while(T--)
{
int n;
cin>>n;
for(int i = 0; i < n; i++) cin>>q[i];
sort(q, q + n);
bool find0 = false, find1 = false;
int p = 0;
while(q[p] <= 1 && p < n)
{
if(q[p] == 0) find0 = true;
if(q[p] == 1) find1 = true;
p++;
} if(find0 && find1)
{
puts("NO");
continue;
} if(!find0 && find1)
{
bool flag = false;
for(int i = 0; i < n - 1; i++)
if(q[i + 1] - q[i] == 1)
{
flag = true;
break;
}
if(!flag) puts("YES");
else puts("NO"); continue;
} puts("YES"); }
}
D
给定一个数,如果这个数可以被k个能够被模k后互不相等的数相加而得到,那么这个数称为k-good数,对于这个n,输出任意一个k即可,没有则为-1
思路:(可以先打表找规律
条件转化一下,很容易就能得到条件是 (n - sum(0, 1, ..., k - 1)) % k == 0;
然后观察奇数,发现2-good可以作用于任意奇数,所以奇数全部输出2
根据上述条件来判断偶数,(n - (k - 1) * k / 2 <求和公式>) % k == 0
如果k是n的因子,并且求和项为整数且小于n,那么一定能输出,观察(k - 1) * k / 2项,发现k要么是奇数,要么是2,这两种情况能让这项为整。
又因为枚举的是偶数,所以我们只需要找到2^p * 最大奇因子 = n即可
2^p * 最大奇因子 = n
先判断临界情况 前两者相等时,一定有n - 求和 = 0,此时n = 2^(2*p) 一定不能输出,此时输出-1,(意思是,n是2^a就输出-1就行)
其他情况,一定一个大于sqrt(n), 一个小于sqrt(n), 小于的数的(n - (k - 1) * k / 2 <求和公式>)一定为正,大于的一定为负
那么输出两者的最小值就行。
代码:
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
#define int long long
#define debug(x) cout << "*" << x << endl;
const int P = 13131;
#define ll long long
const int mod = 1E6 + 7;
const int INF = 0x3f, sINF = 0x3f3f3f3f;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 1e5 + 10;;
int T;
const int UN = 1e9 + 10;
int q[N]; signed main()
{
cin>>T;
while(T--)
{
ll n;
cin>>n;
ll rem = n;
if(n % 2 == 1) cout<<"2"<<endl;
else {
ll k = 1;
while(n % 2 == 0)
{
n /= 2;
k *= 2;
}
if(n == 1) cout<<"-1"<<endl;
else
{ //此时剩下个奇数
k *= 2;
cout<<min(k, n)<<endl; }
} }
}

CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes!) A ~ D的更多相关文章
- Codeforces 1023 A.Single Wildcard Pattern Matching-匹配字符 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)
Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A. Single Wildcard Patter ...
- CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort 暴力枚举,水 1.题意:n*m的数组, ...
- Codeforces Beta Round #27 (Codeforces format, Div. 2)
Codeforces Beta Round #27 (Codeforces format, Div. 2) http://codeforces.com/contest/27 A #include< ...
- Codeforces Round #438 (Div.1+Div.2) 总结
本来兴致勃勃的想乘着这一次上紫,于是很早很早的到了机房 但是好像并没有什么用,反而rating-=47 Codeforces Round #438(Div.1+Div.2) 今天就这样匆匆的总结一下, ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-D. Restore Permutation-构造+树状数组 [Pro ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-C. Magic Grid-构造 [Problem Descripti ...
- Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构
Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)-E. Let Them Slide-思维+数据结构 [Problem ...
- Codeforces Round #792 (Div. 1 + Div. 2) A-E
Codeforces Round #792 (Div. 1 + Div. 2) A-E A 题目 https://codeforces.com/contest/1684/problem/A 题解 思路 ...
- Codeforces Round #792 (Div. 1 + Div. 2) // C ~ E
比赛链接:Dashboard - Codeforces Round #792 (Div. 1 + Div. 2) - Codeforces C. Column Swapping 题意: 给定一个n*m ...
- 【codeforces】【比赛题解】#868 CF Round #438 (Div.1+Div.2)
这次是Div.1+Div.2,所以有7题. 因为时间较早,而且正好赶上训练,所以机房开黑做. 然而我们都只做了3题.:(. 链接. [A]声控解锁 题意: Arkady的宠物狗Mu-mu有一只手机.它 ...
随机推荐
- Solution -「BJWC 2018」「洛谷 P4486」Kakuro
\(\mathcal{Description}\) Link. 有一个 \(n\times m\) 的网格图,其中某些格子被主对角线划成两个三角形,称这样的格子为特殊格:初始时,除了一些障碍格 ...
- NFS共享Nginx网页根目录(自动部署)
IP HOSTNAME SERVICE SYSTEM 192.168.131.132 proxy-nfs nginx+nfs-server CentOS 7.6 192.168.131.131 ngi ...
- Dubbo服务注册到Zookeeper,对外提供服务的实际类 ref(如:SleepServiceImpl)保存在哪里
Dubbo服务注册到Zookeeper,其注册的内容为实际对外提供的服务的实现.这个实现保存在哪里(至于具体客户端使用时怎么取后后续阐述)?可以看看Dubbo如何处理的. 对于@DubboServic ...
- Spring Boot AOP 扫盲,实现接口访问的统一日志记录
AOP 是 Spring 体系中非常重要的两个概念之一(另外一个是 IoC),今天这篇文章就来带大家通过实战的方式,在编程猫 SpringBoot 项目中使用 AOP 技术为 controller 层 ...
- 关于c#知识的学到的新知识点
开头:对这段时间学习的小知识点做一个整理.希望自己能理清思路.当然如果能帮到大家那就更好了. 1.判断写法 !True=false 思考:以前判断一直写if(布尔变量==false),今天看到这个,才 ...
- 搭建Pritunl+Google认证远程连接
搭建Pritunl+Google认证远程连接VPN 基于Centos7安装 Pritunl是一款免费开源的 VPN 平台软件(但使用的不是标准的开源许可证,用户受到很多限制).这是一种简单有效的V ...
- 华为eNSP的防火墙(USG6000V)如何使用Web界面登入
文章目录 华为eNSP的防火墙(USG6000V)如何使用Web界面登入 前言 一.使用步骤 1.导入USG6000V的镜像包 总结 前言 在华为的eNSP的模拟器上如何使用Web界面去管理与使用模拟 ...
- 【01】Spring Boot配置文件相关
1.Spring Boot 获取属性的属性源,优先级从高到低 (1)命令行参数 (2)java:comp/env里的JNDI属性 (3)JVM系统属性 (4)操作系统的环境变量 (5)随机生成的的带r ...
- 【C# .Net GC】强制垃圾回收 和System GC
属性 GC.MaxGeneration:获取系统当前支持的最大代数. 方法 GC.GetTotalMemory(bool forceFullCollection) 方法 true表示该方法先做垃圾收 ...
- C# Debug和Trace:输出调试信息
在 C# 语言中允许在程序运行时输出程序的调试信息,类似于使用 Console.WriteLine 的方式向控制台输出信息.所谓调试信息是程序员在程序运行时需要获取的程序运行的过程,以便程序员更好地解 ...