Codeforces Round #665 (Div. 2) Distance and Axis、
题目链接:Distance and Axis
题意:在ox轴上,给出点A的横坐标x,你可以向左或右移动点A(x+1/x-1),问你最小移动A的次数,以使得可以在ox轴上找到B点位置,B点满足从O到B的距离与从A到B的距离之间的绝对差等于k。
题解:
先特判下:
if(k==0)
{
if(n%2)
printf("1\n");
else printf("0\n");
}
else if(k>=n)
{
printf("%d\n",k-n);
}
对于A点坐标x,最终要移动到哪里,x满足x=2*min(OB,AB)+k
那么枚举OB长度就行,找到距离x点最近那个点就行
为什么不枚举AB,因为枚举它们两个谁,代码都一样
代码:

1 #include<stack>
2 #include<queue>
3 #include<map>
4 #include<cstdio>
5 #include<cstring>
6 #include<iostream>
7 #include<algorithm>
8 #include<vector>
9 #define fi first
10 #define se second
11 #define pb push_back
12 using namespace std;
13 typedef long long ll;
14 const int maxn=2000+10;
15 const int mod=1e9+7;
16 const double eps=1e-8;
17 const int INF = 0x3f3f3f3f;
18 int main()
19 {
20 int t;
21 scanf("%d",&t);
22 while(t--)
23 {
24 int n,k;
25 scanf("%d%d",&n,&k);
26 if(k==0)
27 {
28 if(n%2)
29 printf("1\n");
30 else printf("0\n");
31 }
32 else if(k>=n)
33 {
34 printf("%d\n",k-n);
35 }
36 else
37 { //k+2min(OB,AB)
38 int l=0,r=n,mid,minn=INF;
39 while(l<=r)
40 {
41 mid=(l+r)>>1;
42 int ans=mid*2+k;
43 if(ans>n)
44 {
45 r=mid-1;
46 minn=min(minn,ans-n);
47 }
48 else
49 {
50 l=mid+1;
51 minn=min(minn,n-ans);
52 }
53 }
54 printf("%d\n",minn);
55 }
56 }
57 return 0;
58 }
题目链接:Ternary Sequence
题意:
你有两个序列a,b。序列是由0,1,2构成。给你x1,y1,z1表示a序列中0,1,2的数量,给你x2,y2,z2表示b序列中0,1,2的数量,
如果你构造的a,b序列中,ai==bi,那么结果+0,如果ai>bi,结果加ai*bi。如果ai<bi,结果减ai*bi
让你输出最大结果
题解:
结果想尽可能大,那就先让z1的2和y2的1结合,那么结果这个时候为2*min(z1,y2)
然后如果结果变小,肯定是z2的2和y1的1结合了,那么我们先让z2和x1结合,再和进行完上面操作的z2结合,最后结果减去剩余的z2*2
代码:

1 #include<stack>
2 #include<queue>
3 #include<map>
4 #include<cstdio>
5 #include<cstring>
6 #include<iostream>
7 #include<algorithm>
8 #include<vector>
9 #define fi first
10 #define se second
11 #define pb push_back
12 using namespace std;
13 typedef long long ll;
14 const int maxn=2000+10;
15 const int mod=1e9+7;
16 const double eps=1e-8;
17 const int INF = 0x3f3f3f3f;
18 int main()
19 {
20 int t;
21 scanf("%d",&t);
22 while(t--)
23 {
24 int x1,x2,y1,y2,z1,z2;
25 scanf("%d%d%d",&x1,&y1,&z1);
26 scanf("%d%d%d",&x2,&y2,&z2);
27 int sum=0,ans=min(z1,y2);
28 z1-=ans;
29 y2-=ans;
30 sum=sum+ans*2;
31
32 ans=min(x1,z2);
33 x1-=ans;
34 z2-=ans;
35
36 if(z2)
37 {
38 ans=min(z1,z2);
39 z1-=ans;
40 z2-=ans;
41 if(z2)
42 {
43 sum=sum-z2*2;
44 }
45 }
46 printf("%d\n",sum);
47 }
48 return 0;
49 }
题目链接:Mere Array
题意:
给你一个序列,如果gcd(ai,aj)==序列中的最小值,那么ai和aj可以交换,问你最后能不能把原序列变成一个非递减序列
题解:
我们设序列最小值为minn,我们把可以被minn整除的数找出来,那么剩下数的位置是不能改变的
这个时候我们对原序列sort从小到大排序,判断一下我们要构成的最终序列中,那么不能被minn整除的数的位置改变了没有
如果改变了,那就输出NO,否则YES
毕竟对于可以被minn整除的数来说,它们的位置总是可以通过minn来达到间接互换
代码:

1 #include<stack>
2 #include<queue>
3 #include<map>
4 #include<cstdio>
5 #include<cstring>
6 #include<iostream>
7 #include<algorithm>
8 #include<vector>
9 #define fi first
10 #define se second
11 #define pb push_back
12 using namespace std;
13 typedef long long ll;
14 const int maxn=1e5+10;
15 const int mod=1e9+7;
16 const double eps=1e-8;
17 const int INF = 0x3f3f3f3f;
18 ll v[maxn],w[maxn];
19 int main()
20 {
21 ll t;
22 scanf("%lld",&t);
23 while(t--)
24 {
25 ll n,minn=INF,flag=0;
26 scanf("%lld",&n);
27 for(ll i=1;i<=n;++i)
28 scanf("%lld",&v[i]),w[i]=v[i],minn=min(minn,v[i]);
29 sort(v+1,v+1+n);
30 ll last=0;
31 for(ll i=1;i<=n;++i)
32 {
33 if(v[i]%minn==0) continue;
34 if(v[i]%minn && v[i]==w[i] && last<=w[i]) last=w[i];
35 else
36 {
37 flag=1;
38 break;
39 }
40 }
41 if(flag) printf("NO\n");
42 else printf("YES\n");
43 }
44 return 0;
45 }
Codeforces Round #665 (Div. 2) Distance and Axis、的更多相关文章
- Codeforces Round #665 (Div. 2)
Codeforces Round #665 (Div. 2) A. Distance and Axis 如果\(B\)在\(O\)左边,那么只能是定值\(OA\) 如果\(B\)在\(OA\)中间 ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- Codeforces Round #665 (Div. 2)A-C题解
A. Distance and Axis 题目:http://codeforces.com/contest/1401/problem/A 题解:对于n来说分两种情况,一是奇数,二则是偶数 ①奇数:对于 ...
- Codeforces Round #665 (Div. 2) D. Maximum Distributed Tree 题解(贪心+易错)
题目链接 题目大意 给你一课树,要你给每一条边分权值,每条边的权值大于0,他们的乘积等于k,而且要使得n-1条边1的数量尽可能少,定义 f(u,v)为u到v的边权和求 \(\max \sum_{i=1 ...
- Codeforces Round #665 (Div. 2) D - Maximum Distributed Tree dfs贡献记录
题意: t组输入,每组数据中n个节点构成一棵树,然后给你n-1条边.给你一个m,然后给你m个k的素数因子,你需要给这n-1条边都赋一个权值,这n-1条边的权值之积应该等于k.如果k的素数因子数量小于n ...
- Codeforces Round #665 (Div. 2) D. Maximum Distributed Tree (dfs计数,树)
题意:给你含有\(n\)个节点,\(n-1\)条边的树,以及\(m\)个质数和\(1\),你需要在这\(m\)个质数和一个\(1\)选择数(质数只能选一次,\(1\)可以多选)给\(n-1\)条边赋值 ...
- Codeforces Round #579 (Div. 3) B Equal Rectangles、C. Common Divisors
B Equal Rectangles 题意: 给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等 题解: 原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个 ...
- Codeforces Round #651 (Div. 2) A Maximum GCD、B GCD Compression、C Number Game、D Odd-Even Subsequence
A. Maximum GCD 题意: t组输入,然后输入一个n,让你在区间[1,n]之间找出来两个不相等的数a,b.求出来gcd(a,b)(也就是a,b最大公约数).让你求出来最大的gcd(a,b)是 ...
随机推荐
- 剑指Offer58-左转字符串
题目 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果.对于一个给定的字符序列S,请你把其循环左移K位后的序列输出.例如,字符序列S=" ...
- MySQL常用的数据类型和字段属性
数据类型 数值 tinyint 十分小的数据 1个字节 smallint 较小的数据 2个字节 mediumint 中等大小的数据 3个字节 int 标准的整数 4个字节 常用 bigint 较大的数 ...
- 【win10】win10下两个显示器不同桌面壁纸
win10系统下,双屏显示为不同的桌面壁纸 操作: 1.鼠标右键点击个性化 2.点击背景选项 3.在图片上右键选择要添加为背景的图片 同理,将另一个屏幕壁纸设为监视器1 最后效果为两个分屏为不同桌面壁 ...
- 【Oracle】生成随机数
Oracle生成随机数: dbms_random.string(opt, 6) --括号里的opt要从下面的列表中选择,数字代表要生成几位随机数,如果是1位的话,就改成1 以此类推 opt可取 ...
- three.js cannon.js物理引擎之约束
今天郭先生继续说cannon.js,主演内容就是点对点约束和2D坐标转3D坐标.仍然以一个案例为例,场景由一个地面.若干网格组成的约束体和一些拥有初速度的球体组成,如下图.线案例请点击博客原文. 下面 ...
- Linux下安装配置rocketmq (单个Master、双Master)
一.环境: centos7(2台虚拟机):192.168.64.123:192.168.64.125 apache-maven-3.2.5(官网要求maven版本是3.2.x,版本不同,编译rocke ...
- nokogiri Fail install on Ruby 2.3 for Windows #1456 <From github>
Q: gem install railson nokogiri install fail with error: 'nokogiri requires Ruby version < 2.3, & ...
- 电脑打不开gitHub的解决方法
电脑打不开gitHub的解决方法 方法:修改本地的hosts文件 因为Github是国外网站,所以经常会遇到打不开的问题,并且有时能打开但是网速好慢 解决这个问题的方法是 : C:\Windows ...
- 分布式事务 Seata Saga 模式首秀以及三种模式详解 | Meetup#3 回顾
https://mp.weixin.qq.com/s/67NvEVljnU-0-6rb7MWpGw 分布式事务 Seata Saga 模式首秀以及三种模式详解 | Meetup#3 回顾 原创 蚂蚁金 ...
- 关于MongoDB的简单理解(三)--Spring Boot篇
一.前言 Spring Boot集成MongoDB非常简单,主要为加依赖,加配置,编码. 二.说明 环境说明: JDK版本为15(1.8+即可) Spring Boot 2.4.1 三.集成步骤 3. ...