A. Distance and Axis

题目:http://codeforces.com/contest/1401/problem/A

题解:对于n来说分两种情况,一是奇数,二则是偶数

①奇数:对于k来说如果是奇数且小于等于他,ans=0;若k是奇数并且大于n,则ans=k-n;若k是偶数并且k<n,那么ans=1;若k为偶数并且k>n,则ans=k-n

②偶数:若k为偶数并且k<=n,则ans=0;若k为偶数并且k>n,则ans=k-n;若k为奇数并且k<n,则ans=1;若k为奇数并且k>n,则ans=k-n

代码:

#include<bits/stdc++.h>    //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair using namespace std; const int inf = 0x3f3f3f3f;//无穷大
//const int maxn = ;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii; int main()
{
IOS;
ll t,n,k;
cin>>t;
while(t--)
{
cin>>n>>k;
if(n%==)
{
if(k%==&&k<=n)
cout<<""<<endl;
else if(k%==&&k>n)
cout<<k-n<<endl;
else if(k%==&&k<n)
cout<<""<<endl;
else if(k%==&&k>n)
cout<<k-n<<endl;
}
else
{
if(k%==&&k<n)
cout<<""<<endl;
else if(k%==&&k>n)
cout<<k-n<<endl;
else if(k%==&&k<=n)
cout<<""<<endl;
else if(k%==&&k>n)
cout<<k-n<<endl;
}
}
return ;
}

B. Ternary Sequence

题目:http://codeforces.com/contest/1401/problem/B

题解:若想最大,只有让尽可能多的a数组中的2去匹对b数组中的1,这样就都是正的。但也会存在负数,如何才能达到最大化呢?一道典型的贪心思路问题

首先判断a中2的个数是否大于b中1的个数

若大于b中1的个数,ans=2*y2,在判断a中0的个数和剩下的2的个数是否大于b数组中2的个数,若大于,答案还是ans;若小于,则b数组中剩下的2的个数将要和a数组中的1的个数进行配对,产生负数,则ans-=2*z2

若小于b中的1的个数,ans=2*z1,然后判断a中0的个数是否大于b中2的个数,若大于,答案就是ans;若小于,则b数组中剩下的2的个数将要和a数组中1的个数进行配对,产生负数,则ans-=2*z2

代码:

#include<bits/stdc++.h>    //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair using namespace std; const int inf = 0x3f3f3f3f;//无穷大
//const int maxn = ;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii; int main()
{
IOS;
ll t,x1,x2,y1,y2,z1,z2;
cin>>t;
while(t--)
{
cin>>x1>>y1>>z1;
cin>>x2>>y2>>z2;
ll ans=;
if(z1>=y2)
{
ans+=*y2;
z1-=y2;
if(x1+z1<z2)
{
z2=z2-(x1+z1);
ans-=*z2;
}
}
else
{
ans+=*z1;
if(x1<z2)
{
z2-=x1;
ans-=z2*;
}
}
cout<<ans<<endl;
}
return ;
}

C. Mere Array

题目:http://codeforces.com/contest/1401/problem/C

题解:用两个数组来判断,其一数组来记录数字,另一数组排序形成最终的答案数组。

然后我们理解一下,第i个第j个数交换位置,相当于第i个数先和最小数交换,然后最小数在和第j个数交换。因此,从头到尾对比两个数组,如果数字不一致,判断原来数组是否整除最小数,如果不能整除代表此位置不能交换,因而不会形成最终的不递减数组。

代码:

#include<bits/stdc++.h>    //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair using namespace std; const int inf = 0x3f3f3f3f;//无穷大
const int maxn = ;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii; ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
ll a[maxn],b[maxn];
int main()
{
IOS;
int t,i,j,n,tmp;
cin>>t;
while(t--)
{
cin>>n;
for(i=;i<n;i++)
{
cin>>a[i];
b[i]=a[i];
}
sort(a,a+n);
bool flag=false;
for(i=;i<n;i++)
{
if(a[i]!=b[i])
{
if(b[i]%a[]!=)
{
flag=true;
break;
}
}
}
if(flag==true)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return ;
}

Codeforces Round #665 (Div. 2)A-C题解的更多相关文章

  1. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  2. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  3. Codeforces Round #665 (Div. 2)

     Codeforces Round #665 (Div. 2)  A. Distance and Axis 如果\(B\)在\(O\)左边,那么只能是定值\(OA\) 如果\(B\)在\(OA\)中间 ...

  4. Codeforces Round #198 (Div. 2)A,B题解

    Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...

  5. Codeforces Round #672 (Div. 2) A - C1题解

    [Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...

  6. Codeforces Round #665 (Div. 2) D. Maximum Distributed Tree 题解(贪心+易错)

    题目链接 题目大意 给你一课树,要你给每一条边分权值,每条边的权值大于0,他们的乘积等于k,而且要使得n-1条边1的数量尽可能少,定义 f(u,v)为u到v的边权和求 \(\max \sum_{i=1 ...

  7. Codeforces Round #614 (Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...

  8. Codeforces Round #610 (Div. 2) A-E简要题解

    contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...

  9. Codeforces Round #611 (Div. 3) A-F简要题解

    contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...

随机推荐

  1. Linux企业运维人员最常用命令汇总

    本文目录 线上查询及帮助命令 文件和目录操作命令 查看文件及内容处理命令 文件压缩及解压缩命令 信息显示命令 搜索文件命令 用户管理命令 基础网络操作命令 深入网络操作命令 有关磁盘与文件系统的命令 ...

  2. 恕我直言,我也是才知道ElasticSearch条件更新是这么玩的

    背景 ElasticSearch 的使用度越来越普及了,很多公司都在使用.有做日志搜索的,有做商品搜索的,有做订单搜索的. 大部分使用场景都是通过程序定期去导入数据到 ElasticSearch 中, ...

  3. Day16_授权中心

    学于黑马和传智播客联合做的教学项目 感谢 黑马官网 传智播客官网 微信搜索"艺术行者",关注并回复关键词"乐优商城"获取视频和教程资料! b站在线视频 总结 1 ...

  4. MacOS工具

    原文是"池建强"的微信文章,公众号为"MacTalk" 1. Alfred 2. iTerm2 一些基本功能如下: 分窗口操作:shift+command+d( ...

  5. 一图看懂华为云DevCloud如何应对敏捷开发的测试挑战

    作为敏捷开发中测试团队的一员,在微服务测试过程中,你是不是也遇到同样困惑:服务不具备独立验证能力.自动化用例开发效率很低等? 华为云DevCloud API全场景测试技术来支招~围绕API的全场景,打 ...

  6. 一本通 1783 矩阵填数 状压dp 容斥 计数

    LINK:矩阵填数 刚看到题目的时候感觉是无从下手的. 可以看到有n<=2的点 两个矩形. 如果只有一个矩形 矩形外的方案数容易计算考虑 矩形内的 必须要存在x这个最大值 且所有值<=x. ...

  7. 2019 HL SC day4

    自闭场本来 以为 顶多一些不太会 结果发现 一堆不太会 . 树状数组  感觉 好久没看 了有点遗忘 不过还好 现在我来了.莅临之神将会消灭一切知识点哦. 今天说点不一样东西 树状数组 hh 很有用的东 ...

  8. 阿里云Redis的开发规范

    作者:付磊-起扬 来源:https://yq.aliyun.com/articles/531067 本文主要介绍在使用阿里云Redis的开发规范,从下面几个方面进行说明. 键值设计 命令使用 客户端使 ...

  9. Python生成测试数据-Faker(非LOL选手-李相赫)

    Faker介绍 官方文档:https://faker.readthedocs.io/en/master/ Faker is a Python package that generates fake d ...

  10. wps 2011 破解版软件

    今天换了一台新电脑. wps 都没有 系统的太过忍受不了 整了一天终于是找到了一个合适安装的 想要的邮件发给我  673658917@qq.com