水 A - Wilbur and Swimming Pool

自从打完北京区域赛,对矩形有种莫名的恐惧..

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f; int main(void) {
int n, x[4], y[4];
cin >> n;
for (int i=0; i<n; ++i) {
cin >> x[i] >> y[i];
}
if (n == 1) puts ("-1");
else if (n == 2) {
if (x[0] == x[1] || y[0] == y[1]) puts ("-1");
else {
int ans = abs (x[0] - x[1]) * abs (y[0] - y[1]);
cout << ans << endl;
}
}
else if (n == 3) {
int ans = -1;
if (x[0] == x[1]) {
ans = abs (y[0] - y[1]) * abs (x[2] - x[0]);
}
else if (x[0] == x[2]) {
ans = abs (y[0] - y[2]) * abs (x[1] - x[0]);
}
else if (x[1] == x[2]) {
ans = abs (y[1] - y[2]) * abs (x[0] - x[1]);
}
cout << ans << endl;
}
else {
int ans = -1;
if (x[0] == x[1]) {
ans = abs (y[0] - y[1]) * abs (x[2] - x[0]);
}
else if (x[0] == x[2]) {
ans = abs (y[0] - y[2]) * abs (x[1] - x[0]);
}
else if (x[0] == x[3]) {
ans = abs (y[0] - y[3]) * abs (x[1] - x[0]);
}
cout << ans << endl;
} return 0;
}

贪心(水) B - Wilbur and Array

直接扫一边,记录后面的值.忘开long long

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
ll a[N]; int main(void) {
int n; cin >> n;
for (int i=1; i<=n; ++i) {
cin >> a[i];
}
ll ans = 0;
ll now = 0, oth = 0;
for (int i=1; i<=n; ++i) {
now = oth;
if (now == a[i]) continue;
else if (now < a[i]) {
ll tmp = a[i] - now;
oth += tmp;
ans += tmp;
}
else {
ll tmp = now - a[i];
oth -= tmp;
ans += tmp;
}
}
cout << ans << endl; return 0;
}

贪心+排序 C - Wilbur and Points

题意:给出n个点以及n个w[i],问一个点的序列,使得w[i] = p[j].y - p[j].x,并且保证不出现p[i].x <= p[j].x && p[i].y <= p[j].y (i > j)

分析:其实就是到水题,map映射下,用set + pair来存储点,自动从小到大排序,最后再判序列是否满足题意.tourist的判断代码好神奇,一直怀疑自己读错题,应该是能查看数据的吧.

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
map<int, set<pair<int, int> > >mp;
int w[N];
pair<int, int> ans[N]; int main(void) {
int n; scanf ("%d", &n);
for (int x, y, i=1; i<=n; ++i) {
scanf ("%d%d", &x, &y);
mp[y-x].insert (make_pair (x, y));
}
for (int i=1; i<=n; ++i) {
scanf ("%d", &w[i]);
}
for (int i=1; i<=n; ++i) {
if (mp[w[i]].empty ()) {
puts ("NO"); return 0;
}
ans[i] = *(mp[w[i]].begin ());
mp[w[i]].erase (mp[w[i]].begin ());
}
for (int i=2; i<=n; ++i) {
int x1 = ans[i].first, x2 = ans[i-1].first;
int y1 = ans[i].second, y2 = ans[i-1].second;
if (x1 <= x2 && y1 <= y2) {
puts ("NO"); return 0;
}
}
puts ("YES");
for (int i=1; i<=n; ++i) {
int x = ans[i].first;
int y = ans[i].second;
printf ("%d %d\n", x, y);
} return 0;
}

  

Codeforces Round #331 (Div. 2)的更多相关文章

  1. Codeforces Round #331 (Div. 2) E. Wilbur and Strings dfs乱搞

    E. Wilbur and Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596 ...

  2. Codeforces Round #331 (Div. 2) D. Wilbur and Trees 记忆化搜索

    D. Wilbur and Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

  3. Codeforces Round #331 (Div. 2)C. Wilbur and Points 贪心

    C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...

  4. Codeforces Round #331 (Div. 2) B. Wilbur and Array 水题

    B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

  5. Codeforces Round #331 (Div. 2) A. Wilbur and Swimming Pool 水题

    A. Wilbur and Swimming Pool Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/conte ...

  6. Codeforces Round #331 (Div. 2)【未完待续】

    http://codeforces.com/problemset/problem/596/B GGGGGGGGGGGGGGGGGGG

  7. Codeforces Round #331 (Div. 2) C. Wilbur and Points

    C. Wilbur and Points time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. Codeforces Round #331 (Div. 2) _A. Wilbur and Swimming Pool

    A. Wilbur and Swimming Pool time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. Codeforces Round #331 (Div. 2) B. Wilbur and Array

    B. Wilbur and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. zoj.3865.Superbot(bfs + 多维dp)

    Superbot Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbot is an interesting game which you ...

  2. java笔记--查看和修改线程的优先级

    查看和修改线程的优先级 java中每一个线程都有优先级属性,在默认情况下,新建的线程的优先级与创建该线程的线程优先级相同.每当线程调度器选择要运行的线程时,通常选择优先级较高的线程. 注:线程的优先级 ...

  3. Intent的Flag

    小段代码: Intent it=new Intent(); it.setClass(Setting.this,Main.class);//从Setting跳转到Main it.addFlags(Int ...

  4. bmob

    移动后台: bmob http://baike.baidu.com/link?url=GHdwJY3cGygcfQDdzosckQnhVy1pvIGZA2Ws0K26lSSFGu7QRX4R1wlo6 ...

  5. 学习windows内核书籍推荐 ----------转自http://tieshow.iteye.com/blog/1565926

      虽然,多年java,正在java,看样子还得继续java.(IT小城,还是整java随意点)应用程序 运行于操作系统之上,  晓操作系统,方更晓应用程序. 主看windows,因为可玩性高,闭源才 ...

  6. MVC 修饰标签

    MVC中的修饰标签有很多用途.它以修饰标签形式应用在控制器或控制器中的动作上. 最先想到的就是AcceptVerbs标签,在创建的时候,如果导航到创建视图,但不创建,则: public ActionR ...

  7. TFS和VSS的简单对比

    概念: TFS:Team Foundation Server(通常记作“TFS”) 是一种为 Microsoft 产品提供 源代码管理. 数据收集. 报告和项目跟踪,而为协作 软件开发 的项目. 可作 ...

  8. ubuntu 15 安装Qt

    Linux 下安装 QT5.4.0      http://blog.163.com/xd8171@126/blog/static/620810432015027111314471/ Linux qt ...

  9. volatile关键字

    [本文链接] http://www.cnblogs.com/hellogiser/p/volatile.html [分析] volatile 关键字是一种类型修饰符,用它声明的类型变量表示可以被某些编 ...

  10. 47. 数组中出现次数超过一半的数字[Number appears more than half times]

    [题目]:数组中有一个数字出现的次数超过了数组长度的一半,找出这个数字. 例如长度为9的数组{1,2,3,2,2,2,5,4,2}中次数超过了数组长度的一半的数字为2,而长度为8的数组{1,2,3,2 ...