Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock
来源:互联网 发布:软件体系架构 pdf 编辑:程序博客网 时间:2024/05/17 06:51
题目链接: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;}
0 0
- Codeforces Round #229 (Div. 2)A. Inna and Alarm Clock
- Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock
- Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock
- Codeforces Round #229 (Div. 2) Inna and Alarm Clock
- codeforces 390A Inna and Alarm Clock
- codeforces Inna and Alarm Clock
- A. Inna and Alarm Clock
- Codeforces 390A Inna and Alarm Clock(水题)
- 390A. Inna and Alarm Clock
- CF 390A:Inna and Alarm Clock
- Inna and Alarm Clock
- Codeforces Round #234 (Div. 2) :A. Inna and Choose Options
- Codeforces Round #234 (Div. 2) A. Inna and Choose Options
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2)B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes
- Mali GPU OpenGL ES 应用性能优化--测试+定位+优化流程
- "n\x45y\123\t"长度
- Insert Interval Array
- Android 进阶学习:Android自定义View的实现方法,带你一步步深入了解View(四)
- Xcode_缓存清理
- Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock
- sql中DISTINCT的用法
- HttpServletRequest对象
- Android 进阶学习:事件分发机制完全解析,带你从源码的角度彻底理解(上)
- linux学习笔记
- sql中GROUP BY的使用
- Android事件分发机制完全解析,带你从源码的角度彻底理解(下)
- 【Effective C++ 读书笔记】条款04:确定对象使用前已先被初始化
- Updata Android SDK