nyoj-1115-y的最大值(变态最大值二)

2024-06-10 14:32
文章标签 最大值 nyoj 变态 1115

本文主要是介绍nyoj-1115-y的最大值(变态最大值二),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

y的最大值(变态最大值二)

时间限制: 1000 ms  |  内存限制: 65535 KB
难度: 1
描述
给定n对整数,每对有一个x,y(都为正整数),要求是我们先对每个数对排序之后,再找出变态最大值(y的最大值)。排序规则是:我们让x由小到大排,当x相等的时候y大的放到后面。然后三个数对一组,编号为1..n/3(n为3的倍数),奇数组找出最大值,偶数组找出最小值,然后求出这些数的最大值
输入
有多组测试数据
每组数据一个n代表n组数对(0<n<1000且n为3的倍数)
接下来n行每行有两个数x,y(都为正整数)
输出
输出只有一行,每行一个数变态最大值
样例输入
6
2 3
3 4
1 3
6 3
1 4
1 2
样例输出
4
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct in
{int x;int y;
}a[1005];
int b[1005];
int cmp(const void*a,const void *b)
{struct in *c=(struct in *)a;struct in *d=(struct in *)b;if(c->x!=d->x) return c->x-d->x;else return c->y-d->y;
}
int main()
{int n,i;while(cin>>n){int maxy=0,miny=0,m=0;int d=1,t=0,k=0;for(i=0;i<n;i++)cin>>a[i].x>>a[i].y;qsort(a,n,sizeof(a[0]),cmp);for(i=0;i<n;){if(d%2!=0){maxy=a[i].y;for(t=1;t<3;t++){maxy=max(maxy,a[i+t].y);}i+=3;m=max(m,maxy);}else{ miny=a[i].y;for(t=1;t<3;t++){miny=min(miny,a[i+t].y);}i+=3;m=max(m,miny);}d++;}cout<<m<<endl;}return 0;
}


这篇关于nyoj-1115-y的最大值(变态最大值二)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1048423

相关文章

nyoj 288 士兵杀敌(五)

一道插线问线离线版的题  复杂度O(n); 代码如下: #include<stdio.h>#include<string.h>const int M = 1000003;const int mod=10003;int num[M];int main(){int n,c,q;scanf("%d%d%d",&n,&c,&q);while(c--){int a,b,x;scan

nyoj 1037 Postscript of Tian Ji racing

一道卡贪心的题。 也算一道改编题。 此题的解法推荐为二分图的最大匹配。 首先将输入数据转换一下,然后将满足题意的一组牌建立条边,最终边的覆盖数即为 LN 最后可得的分数。 然后求出最大匹配即可。 代码如下: #include<stdio.h>#include<string.h>char card[30][5];char s[5];int map[30][30];

nyoj 1002 Trucking

同样一道改编题。 只要把题意理解了好。 简单的二分加最短路。 只要二分高度, 然后求最短路,输出满足题意的即可。 代码如下: (最短路用spfa 时间效率高) #include <iostream>#include <cstdio>#include <cstring>#include <ctime>#include <queue>using namespace st

nyoj 1072 我想回家

一道相当题目描述相当扯的题。 这道题目的描述最后说的是求出到达最后一个点的最短距离,所以输入数据最后输入的城堡的坐标是没用的。 就是先求出两点之间的距离,若不大于村落间距离,并且不大于最后的距离限制 l ,则在两点间建边。 最后任意方法求出最短路即可。 #include <iostream>#include<stdio.h>#include<vector>#include<

nyoj 1038 纸牌游戏

poj 的一道改编题,说是翻译题更恰当,因为只是小幅度改动。 一道模拟题,代码掌控能力比较好,思维逻辑清晰的话就能AC。 代码如下: #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;struct node{char c[5];int rk;char da[5];int nu

nyoj 685 查找字符串

当初一开始没做出来。 后来,学习过一段时间之后,在返回来做这道题,忽然发现,map类容器可以做。 PS:需要注意的是:此题如果用c++的输入输出的话,会超时。 O(time):gets()<  scanf() < cin。   附上代码: #include<stdio.h>#include<map>#include<string>#include<string.h>usin

nyoj 695 Judging Filling Problems

一道强大的模拟题。。。 只要学会<string>类的运用即可。。。 注意: 1、细节的处理。 2、问题的分情况讨论。。 附上代码: 有好对缀余的地方,希望大神前来更新。 #include<stdio.h>#include<string.h>#include<string>#include<iostream>using namespace std;int num[1000

【C++二分查找】2439. 最小化数组中的最大值

本文涉及的基础知识点 C++二分查找 LeetCode2439. 最小化数组中的最大值 给你一个下标从 0 开始的数组 nums ,它含有 n 个非负整数。 每一步操作中,你需要: 选择一个满足 1 <= i < n 的整数 i ,且 nums[i] > 0 。 将 nums[i] 减 1 。 将 nums[i - 1] 加 1 。 你可以对数组执行 任意 次上述操作,请你返回可以得到的 n

【hdu】I Hate It(线段树,结点修改求区间最大值)

线段树的模板题,还是二分递归。 #include <iostream>#include <cstdlib>#include <cstdio>#include <string>#include <cstring>#include <cmath>#include <vector>#include <queue>#include <set>#include <map>#incl

SQL文:求最大值问题

SQL文:求最大值问题 在判定流程中的“一级审理节点”查找最新审批数据 select a.workitemid, a.workitemname, a.endtime, a.processinstid from WFWORKITEM a where a.workitemid in (select max(b.workitemid) from WFWORKITEM b where b.workitem