水 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. Java中的异常

    一.什么是异常 异常就是在程序的运行过程中所发生的不正常的事件,如所需文件找不到,网络连接不通或中断,算术运算出错(如被0除),数组下标越界,装载了一个不存在的类,对null的操作,类型转换异常等等. ...

  2. 小白科普之JavaScript的函数

    一 概述 1.1 函数声明 (1)function命令 函数就是使用function命令命名的代码区块,便于反复调用.这种声明方式叫做函数的声明(Function Declaration). func ...

  3. Unity3d与iOS交互开发——接入平台SDK必备技能

    原地址:http://www.2cto.com/kf/201401/273337.html# 前言废话:开发手机游戏都知道,你要接入各种平台的SDK.那就需要Unity3d与iOS中Objective ...

  4. Objective-C和其他C指针的转换

    首先看一下典型的NSString与CFStringRef的相互转换   http://www.tuicool.com/articles/MJRr226 // CFStringRef to NSStri ...

  5. BeautifulSoup获取指定class样式的div

    如何获取指定的标签的内容是解析网页爬取数据的必要手段,比如想获取<div class='xxx'> ...<div>这样的div标签,通常有三种办法, 1)用字符串查找方法,然 ...

  6. NGINX userid 分析、解码

    NGINX userid 分析.解码 生成userid的代码在 http/modules/ngx_http_userid_filter_module.c 大概550行左右. uid_set 是4个ui ...

  7. shell脚本的调试技巧

    请参考文章:http://www.ibm.com/developerworks/cn/linux/l-cn-shell-debug/index.html 读后的感觉,还是用shell的选项灵活,方便. ...

  8. c++0x新特性实例(比较常用的)

    //array #include <array> void Foo() { array<> a; generate(a.begin(),a.end(),rand); sort( ...

  9. 低配置电脑播放 flash 视频时 占 cpu 资源过高的解决方法

    安装低版本的 flash player 版本, 经调试能满足播放的最低版本是 Flash Player 10.3.183.90 然后 firefox 3.6.28 + Adblock Plus 2.0 ...

  10. 解决 mysql 启动报错--发现系统错误2,系统找不到指定的文件

    HKEY_LOCAL_MACHINE-SYSTEM-CurrentControlSet-services-mysql(服务名)-ImagePath 更改为(自己的):"C:\Program ...