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有一只手机.它 ...
随机推荐
- Python内置模块(re+collections+time等模块)
Python内置模块(re+collections+time等模块) 1. re模块 import re 在python要想使用正则必须借助于模块 re就是其中之一 1.1 findall功能( re ...
- c++ StrVec等效vector(string)的类
c++ StrVec等效vector<string>的类 知识点 静态成员变量要在类外定义和初始化 allocator类是使用和uninitialized_copy的配合使用,实现stri ...
- Grafana v8.3.3 & jmeter-influxdb2-backend
1. 说明 接上篇文章,今天继续聊Grafana & influxdb2-backend. 2. Grafana v8.3.3安装 下载rpm包 wget https://dl.grafana ...
- Spring Boot数据访问之多数据源配置及数据源动态切换
如果一个数据库数据量过大,考虑到分库分表和读写分离需要动态的切换到相应的数据库进行相关操作,这样就会有多个数据源.对于一个数据源的配置在Spring Boot数据访问之数据源自动配置 - 池塘里洗澡的 ...
- zabbix-agentd;客户端开启多个端口。
学习标杆:https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/8/html/configuring_basic ...
- WPF + Winform 解决管理员权限下无法拖放文件的问题
wpf,winform混合解决管理员权限无法拖放文件的问题 学习自: https://zhuanlan.zhihu.com/p/343369663 https://zhuanlan.zhihu.com ...
- Spring Security即将弃用WebSecurityConfigurerAdapter配置类
用过WebSecurityConfigurerAdapter的都知道对Spring Security十分重要,总管Spring Security的配置体系.但是马上这个类要废了,你没有看错,这个类将在 ...
- Session、Session共享、Token演变
巨人的肩膀 深夜,我偷听到程序员要对session下手-- (qq.com)
- Python-Flask框架之"图书管理系统"项目,附详解源代码及页面效果截图
该图书管理系统要实现的功能如下: 1. 可以通过添加窗口添加书籍或作者,如果要添加的作者和书籍已存在于书架上, 则给出相应的提示: 2. 如果要添加的作者存在,而要添加的书籍书架上没有,则将该书籍添加 ...
- 数据分析工具那么多,掌握Smartbi这一个就够了!
经常听见有人问,数据分析用什么工具好? 被大家熟知的数据分析工具有很多,比如Excel.BI.R.Python--具体选择哪个这要看个人的需求,如果非要说哪个好,其中BI工具小编觉得"老少皆 ...