Yedl的专栏

Stay hungry, stay foolish

Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock

题目链接:http://codeforces.com/contest/390/problem/A
题意:设置n个闹钟,给你每个闹钟的位置,选择竖列消除或者横行消除(只能用一种),问你关闭所有闹钟最小的操作数;
思路:横着扫一遍,竖着扫一遍,求较小值即可。
代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5+10;
struct node
{
	int x, y;
}p[N];

int n;

bool cmp1(node b, node c)
{
	if(b.x != c.x) return b.x < c.x;
}

bool cmp2(node b, node c)
{
	if(b.y != c.y) return b.y < c.y;
}

int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d%d", &p[i].x, &p[i].y);
	}
	int ans1 = 1, ans2 = 1;
	sort(p, p+n, cmp1);
	for(int i = 1; i < n; i++)
	{
		if(p[i].x == p[i-1].x)continue;
		else ans1++;
	}
	sort(p, p+n, cmp2);
	for(int i = 1; i < n; i++)
	{
		if(p[i].y == p[i-1].y) continue;
		else ans2++;
	}
	int ans = min(ans1, ans2);
	printf("%d\n", ans);
	return 0;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Doris1104/article/details/46779455
文章标签: codeforces
个人分类: CodeForces 水题
上一篇Codeforces Round #311 (Div. 2) D. Vitaly and Cycle
下一篇Codeforces Round #229 (Div. 2)B. Inna, Dima and Song
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭