水 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. POJ 1260 Pearls

    Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6670 Accepted: 3248 Description In ...

  2. cocos2dx新研发的游戏,手机运行时非常热的解决方案

    cocos2dx新研发的游戏,手机运行时非常热,有需要的朋友可以参考下. cocos2dx新研发的游戏,手机上运行时导致手机非常热,后来听其他项目组分享时得知,可以通过降帧解决这个问题,原来是coco ...

  3. [POJ1050]To the Max

    [POJ1050]To the Max 试题描述 Given a two-dimensional array of positive and negative integers, a sub-rect ...

  4. BZOJ2904

    找了一个晚上的资料,拼凑出来这么一个东西: 1) 如果是完全平方数返回12) 如果可以表示成形如$x^2+y^2$的形式输出2.这要求该数质因数分解后形如$4k+3$的质因数次数都是偶数.3) 如果该 ...

  5. SSDB 数据库如何换用 rocksdb 引擎?

     牧童遥指杏花村,一枝红杏出墙来… SSDB 数据库如何换用 rocksdb 引擎? idea's blog 2014-04-12 71 阅读 rocksdb NoSQL SSDB 数据库使用的是 G ...

  6. iOS7总显示状态栏的解决方法

    转载http://blog.csdn.net/langresser_king/article/details/18351021 2014年2月份开始,苹果需求开发者必须使用xcode5开发游戏和应用, ...

  7. [转]C程序内存区域分配(5个段作用)

    [转]C程序内存区域分配(5个段作用) 2012-08-10 14:45:32|  分类: C++基础|字号 订阅     参考:http://www.360doc.com/content/11/03 ...

  8. 22.python笔记之web框架

    一.web框架本质 1.基于socket,自己处理请求 #!/usr/bin/env python3 #coding:utf8 import socket def handle_request(cli ...

  9. 快速排序模板qsort(转载)

     qsort  用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(const void *,const void *)); 各 ...

  10. codeforces 374A Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...