Codeforces Round #707 (Div. 2)
比赛传送门:
Codeforces Round #707 (Div. 2)
A. Alexey and Train
思路:
按题意模拟即可
AC Code
#include<bits/stdc++.h>
using namespace std;
int a[105],b[105],t[105];
int main()
{int d;scanf("%d",&d);while(d--){int n;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]);for(int i=1;i<=n;i++) scanf("%d",&t[i]);int res=0;for(int i=1;i<=n;i++){res=res+a[i]-b[i-1]+t[i];if(i==n) break;int f=(b[i]-a[i])/2;if((b[i]-a[i])%2) f++;res=res+f;if(res<b[i]) res=b[i];}printf("%d\n",res);}//system("pause");return 0;
}
B. Napoleon Cake
题目大意:
给你n层,第 i 层上面有 a i层奶油,奶油会向下渗透,多余的会浪费掉。问最后有每一层是否有奶油。
AC Code
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],f[N];
int main()
{int t;scanf("%d",&t);while(t--){int n;scanf("%d",&n);for(int i=0;i<=n+1;i++) f[i]=0;for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]>0){int st=i-a[i]+1;st=max(st,1);f[st]++;f[i+1]--;}}for(int i=1;i<=n;i++){f[i]=f[i-1]+f[i];if(f[i]>=1) printf("1 ");else printf("0 ");}printf("\n");}//system("pause");return 0;
}
C. Going Home
题目大意:
给你一个整数序列,问你能不能找到下标不同的4个数使得 ax+ay=az+aw
思路:
我在正向考虑了很久之后一直都想不到一个合适的时间复杂度的思路。于是我移项了一下ax-az=aw-ay。也就是两对数的差相等。那么最坏的情况下就是没有两对数的差相等,那么排序之后相邻两数的差也都不相等,于是我们可以构造出一个
1 2 4 7 11 16 22……的序列
那么按照题目的数据范围这个序列的长度最多也就3e3左右。那么意味着什么呢,当n>3e3时,我们排序之后,相邻的两个数做差,必然有两对相邻的数的差是相等的。当n<3e3时,我们两个循环暴力找即可。还有一些需要注意的细节见代码。
AC Code
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,M=5e6+10;
pair<int,int>a[N];
map<int,int>mp;
int x[M],y[M];
int main()
{int n;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i].first);a[i].second=i;}sort(a+1,a+1+n);if(n<=3e3){for(int i=1;i<n;i++){for(int j=i+1;j<=n;j++){int p=a[i].first+a[j].first;mp[p]++;if(mp[p]==1){x[p]=a[i].second;y[p]=a[j].second;}else{if(x[p]!=a[i].second&&x[p]!=a[j].second&&y[p]!=a[i].second&&y[p]!=a[j].second){printf("YES\n");printf("%d %d %d %d\n",x[p],y[p],a[i].second,a[j].second);//system("pause");return 0;}}}}} else{for(int i=n;i>1;i--){int d;d=a[i].first-a[i-1].first;mp[d]++;if(mp[d]==1) x[d]=i;else {if(i+1!=x[d]){printf("YES\n");printf("%d %d %d %d\n",a[i-1].second,a[x[d]].second,a[i].second,a[x[d]-1].second);//system("pause");return 0;}}}}printf("NO\n");//system("pause");return 0;
}
侥幸上了波大分,快乐了,哈哈哈哈
Codeforces Round #707 (Div. 2)相关推荐
- Codeforces Round #777 (Div. 2) 简训
Codeforces Round #777 (Div. 2) 简训 导语 涉及的知识点 题目 A Madoka and Math Dad B Madoka and the Elegant Gift C ...
- Codeforces Round #815 (Div. 2)
Codeforces Round #815 (Div. 2) 传送门 :Codeforces Round #815 (Div. 2) 之前都是108键的键盘,最近在家用的68,两三天了还是非常不顺手, ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...
- F. Bouncy Ball(Codeforces Round 859 (Div. 4))
题目链接:Problem - F - Codeforceshttps://codeforces.com/contest/1807/problem/F 题意:给你一个n*m大小的网格,再给你一个起始点和 ...
- D. Boboniu Chats with Du(Codeforces Round #664 (Div. 2) )
感受 怎么这么傻逼的题目,我现场A不了呢?看来还有不少提升的空间怎么这么傻逼的题目,我现场A不了呢?看来还有不少提升的空间怎么这么傻逼的题目,我现场A不了呢?看来还有不少提升的空间 题意 简单来说,给 ...
- Codeforces Round #626 (Div. 2)
A 这个似乎出过一遍了?选一个偶数或者两个奇数. B 题意: 给你nnn个数a1,a2,a3,a4......ana_1,a_2,a_3,a_4......a_na1,a2,a3,a4.... ...
- F. Strange Array(Codeforces Round #727 (Div. 2))(主席树)
F. Strange Array 给定一个长度为nnn的数组aaa,1≤ai≤n1 \leq a_i \leq n1≤ai≤n,对于每个aia_iai,我们要找到一个l≤i,r≥il \leq i ...
- E. Company(Codeforces Round #520 (Div. 2))
E. Company 给定一颗有nnn个节点的树,有mmm次询问,每次询问给定[l,r][l, r][l,r],我们可以选择删除其中的一个点ppp,然后找到一个深度最深的rtrtrt,使得剩下的点都在 ...
- D. Cut and Stick(Codeforces Round #716 (Div. 2))
D. Cut and Stick 给定一个长度为nnn的数组,里面元素为a1,a2,a3,-,an−1,an,(1≤ai≤n)a_1, a_2, a_3, \dots, a_{n- 1}, a_n, ...
- Codeforces Round #723 (Div. 2)B. I Hate 1111(完全背包)
problem B. I Hate 1111 time limit per test1 second memory limit per test256 megabytes inputstandard ...
最新文章
- django性能优化缓存view详解
- java虚拟机10.内存模型与线程
- 【牛客 - 1080D】tokitsukaze and Event(最短路,思维)
- 6月8日云栖精选夜读:mac下eclipse配置tomcat无法启动问题
- a类怎么引用b类java_Java中A类的数组如何传入B类???急
- -bash : ** : command not found的问题解决(图文详解)
- 百度安装php环境,Centos下安装类百度文库环境
- Spring.NET企业架构实践之 Nhibernate + WCF + ASP.NET MVC + NVelocity 对PetShop4.0重构(三)——持久层...
- opencv在linux设置环境变量,linux下设置opencv环境变量
- 请问python语言的语法特点_Python3笔记004- 2.1 python的语法特点
- centos7.0KVM虚拟化
- 计算机网络中的mac全称,计算机网络中MAC地址与IP地址
- 哨兵系列卫星_美国宇航局 quot;哨兵6quot;海平面与气候观测卫星发射任务将于11月进行...
- 学python还是labview_Labview个人感受
- 20210928 | Python案例:构建税费计算函数
- 计算机上无法获取,电脑无法获取有效ip 修复ip地址配置方法
- 如何使用idea生成Doc文档
- 10.32/10.33 rsync通过服务同步 10.34 linux系统日志 10.35 scre
- Notice: Undefined index: 提示解决方法
- word指定页插入页码