水 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. cocos基础教程(5)数据结构介绍之cocos2d::Map<K,V>

    1.概述 cocos2d::Map<K,V> 是一个内部使用了 std::unordered_map的关联容器模版. std::unordered_map 是一个存储了由key-value ...

  2. codeforces 258div2 B Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 解题报告:给出一个序列,要你判断这个序列能不能通过将其中某个子序列翻转使其成为升序的序列. 我的做法有 ...

  3. Leetcode 之Construct Binary Tree(52)

    根据先序和中序构造二叉树.根据中序和后序构造二叉树,基础题,采用递归的方式解决,两题的方法类似.需要注意的是迭代器的用法. //先序和中序 TreeNode *buildTree(vector< ...

  4. PHPStorm+Wamp+Xdebug+Windows7调试代码

    Wamp 集成环境 PHPStorm+Xdebug 调试代码 2013.04.16 花了两个小时时间终于 , 配置成功了 ! 我的开发环境如下 , 其它环境也可以参考我的配置 开发环境 : Windo ...

  5. RO05 - 如何编写RemObjects SDK服务端 (Delphi Version)

    转载:http://blog.csdn.net/henreash/article/details/2261134 本文档向你展示如何使用RemObjects(Delphi版)创建第一个服务.读了本文档 ...

  6. 常州Day4题解

    1. 高精度 这题略水,字符串可过,还不加压位等,操作只有BitShift和add/sub,不过编程复杂度有些高.(输出都是二进制我能说些什么...) 2. N皇后问题 (警告! 不是平时你见到的N皇 ...

  7. call_user_func_array使用原型

    If you need to call object and class methods in PHP < 4.0.4, the following code ought to do the t ...

  8. 使用virtualenv搭建独立的Python环境

    virtualenv可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解决包冲突问题. 一.安装virtualenv virtualenv实际上是一个pyth ...

  9. C# 代理/委托 Delegate

    本文转载自努力,努力,努力 1. 委托的定义:委托是函数的封装,它代表一"类"函数.他们都符合一定的签名:拥有相同的参数列表,返回值类型.同时,委托也可以看成是对函数的抽象,是函数 ...

  10. IIS安装时,添加/编辑应用程序扩展名映射 确定按钮不可用。

    原因是:执行文件的路径太长,需要激活按钮. 方法一:选择较短路径的执行文件,先激活按钮. 方法二:点击该路径,就可以激活确认按钮了.