codeforces #321 DIV2
2024-09-20 18:07:05
A题:
链接:http://codeforces.com/contest/580/problem/A
dp,最长连续不上升子序列
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=;
int a[maxn],dp[maxn];
int main()
{
int n;
while(cin>>n)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<n;i++)
{
if(a[i-]<=a[i])
dp[i]=dp[i-]+;
else
dp[i]=;
}
int mx=;
for(int i=;i<n;i++)
if(dp[i]>mx)
mx=dp[i];
cout<<mx<<endl;
}
return ;
}
B题:
链接:http://codeforces.com/contest/580/problem/B
贪心,先按照m升序排序,然后找出符合条件且最大的
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=;
typedef struct
{
long long m,s;
}point;
point p[maxn];
bool cmp(point a,point b)
{
return a.m<b.m;
}
int main()
{
long long n,d;
while(cin>>n>>d)
{
for(int i=;i<n;i++)
cin>>p[i].m>>p[i].s;
sort(p,p+n,cmp);
long long ans=;
long long cnt=;
int j=;
for(int i=;i<n;i++)
{
cnt+=p[i].s;
while(p[i].m-p[j].m>=d)
{
cnt-=p[j].s;
j++;
}
ans=max(ans,cnt);
}
cout<<ans<<endl;
}
return ;
}
C、D、E赛场上没有搞出来,抽时间来补上
最新文章
- 理解 Keystone 核心概念 - 每天5分钟玩转 OpenStack(18)
- Spring中servletFileUpload完成上传文件以及文本的处理
- JSP导入EXCEL样式
- [LeetCode]题解(python):062 Unique path
- C#使用SQL存储过程完整流程
- js与C#之间相互调用的一些方法
- “Cache-control”常见的取值有private、no-cache、max-age、must-revalidate等
- 【转】Centos 设置IP地址的几种方式
- django 自定义过滤器(filter)处理较为复杂的变量的实例
- Mybatis整理_01
- [机器学习Lesson 2]代价函数之线性回归算法
- 【我们一起写框架】MVVM的WPF框架(五)—完结篇
- Android 音视频开发(七): 音视频录制流程总结
- 痞子衡嵌入式:飞思卡尔Kinetis系列MCU启动那些事(1)- KBOOT架构
- Python生产者producer和consumer消费者案例写法,含有多线程,包含队列queue、JoinableQueue队列的用法
- Mac影音多媒体工具软件推荐
- 通过DMS连接RDS需要添加的DMS白名单地址
- How to set up github to work with Visual Studio 2013
- 103. Binary Tree Zigzag Level Order Traversal (Tree, Queue; BFS)
- 设计师别浪费时间啦,快来试试这款Sketch标注插件吧