水 A - Pasha and Stick

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f; int main(void) {
int n; scanf ("%d", &n);
int ans = n / 4;
if (n % 4 == 0) {
ans--;
}
if (n % 2 != 0) ans = 0;
printf ("%d\n", ans); return 0;
}

构造+贪心 B - Vika and Squares

题意:给你一堆油漆,然后选择一个油漆开始涂,一个油漆一个油漆的涂,就是涂过4后面涂5,涂过n后面可以涂1,一直涂到不能继续就停止,问最多能涂多少块

有段时间了,都不知道当时自己怎么做出来的了。

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
int a[N]; int main(void) {
int n; scanf ("%d", &n);
int mn = INF;
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
if (a[i] < mn) mn = a[i];
}
vector<int> pos;
for (int i=1; i<=n; ++i) {
if (a[i] == mn) {
pos.push_back (i);
}
}
int mx_len = 0, sz = pos.size ();
for (int i=0; i<sz-1; ++i) {
mx_len = max (mx_len, pos[i+1] - pos[i] - 1);
}
mx_len = max (mx_len, n - pos[sz-1] + pos[0] - 1);
printf ("%I64d\n", 1ll * n * mn + mx_len); return 0;
}

找规律 C - Harmony Analysis

题意:(1 << k)边长的矩形,第i行与第j行乘积和为0的方案

分析:因为每次都乘2,构造方法:比如++ 变成++ ++那么对应的有-- ++; 再如-++- 变成 -++- -++- 那么对应的有+--+ +--+

#include <bits/stdc++.h>

int a[522][522];

int main(void)  {
int k; scanf ("%d", &k);
int tot = 1;
int len = 1 << k;
a[1][1] = 1;
for (int j=1; j<len; j<<=1) {
int t = tot;
for (int l=1; l<=t; ++l) {
for (int m=1; m<=j; ++m) {
a[l][m+j] = a[l][m];
}
tot++;
for (int m=1; m<=2*j; ++m) {
if (m <= j) a[tot][m] = 1 - a[l][m];
else a[tot][m] = a[l][m];
}
}
}
for (int i=1; i<=len; ++i) {
for (int j=1; j<=len; ++j) {
if (a[i][j] == 1) printf ("+");
else printf ("*");
}
puts ("");
} return 0;
}

  

离线+扫描线+线段树 D - Vika and Segments

题意:给一些横线或者竖线,问一共有多少个点(重复的算一次)

分析:可以转换成求矩形面积的问题,把矩形左下角的点x1--, y1--构成一个宽度为1的矩形,点的个数:x2 - x1,那么面积就是点的个数,离散后加成端更新就可以了。

#include <bits/stdc++.h>

typedef long long ll;
const int N = 1e5 + 5;
struct Seg {
int l, r, h, c;
Seg() {}
Seg(int l, int r, int h, int c) : l (l), r (r), h (h), c (c) {}
bool operator < (const Seg &a) const {
return h < a.h || (h == a.h && l < a.l);
}
};
Seg seg[N<<1];
int X[N<<1]; #define lson l, mid, o << 1
#define rson mid, r, o << 1 | 1
struct Segment_Tree {
int sum[N<<3], cover[N<<3];
void push_up(int l, int r, int o) {
if (cover[o]) {
sum[o] = X[r] - X[l];
}
else if (l + 1 == r) {
sum[o] = 0;
}
else {
sum[o] = sum[o<<1] + sum[o<<1|1];
}
}
void build(int l, int r, int o) {
sum[o] = cover[o] = 0;
if (l + 1 == r) return ;
int mid = l + r >> 1;
build (lson); build (rson);
}
void updata(int ql, int qr, int c, int l, int r, int o) {
if (ql <= l && r <= qr) {
cover[o] += c;
push_up (l, r, o);
return ;
}
else if (l + 1 == r) return ;
int mid = l + r >> 1;
if (ql <= mid) updata (ql, qr, c, lson);
if (qr > mid) updata (ql, qr, c, rson);
push_up (l, r, o);
}
}st; int n, totx, tots; ll run(void) {
ll ret = 0;
std::sort (seg, seg+tots);
std::sort (X, X+totx);
totx = std::unique (X, X+totx) - X;
st.build (0, totx - 1, 1);
for (int i=0; i<tots-1; ++i) {
int l = std::lower_bound (X, X+totx, seg[i].l) - X;
int r = std::lower_bound (X, X+totx, seg[i].r) - X;
st.updata (l, r, seg[i].c, 0, totx - 1, 1);
ret += 1ll * st.sum[1] * (seg[i+1].h - seg[i].h);
}
return ret;
} int main(void) {
scanf ("%d", &n);
int x1, y1, x2, y2;
totx = tots = 0;
for (int i=0; i<n; ++i) {
scanf ("%d%d%d%d", &x1, &y1, &x2, &y2);
if (x1 > x2 || y1 > y2) {
std::swap (x1, x2); std::swap (y1, y2);
}
x1--; y1--;
seg[tots++] = Seg (x1, x2, y1, 1);
seg[tots++] = Seg (x1, x2, y2, -1);
X[totx++] = x1; X[totx++] = x2;
}
printf ("%I64d\n", run ()); return 0;
}

  

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

  1. Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线

    D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...

  2. Codeforces Round #337 (Div. 2) C. Harmony Analysis 构造

    C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester i ...

  3. Codeforces Round #337 (Div. 2) B. Vika and Squares 贪心

    B. Vika and Squares 题目连接: http://www.codeforces.com/contest/610/problem/B Description Vika has n jar ...

  4. Codeforces Round #337 (Div. 2) A. Pasha and Stick 数学

    A. Pasha and Stick 题目连接: http://www.codeforces.com/contest/610/problem/A Description Pasha has a woo ...

  5. Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)

    题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...

  6. Codeforces Round #337 (Div. 2) C. Harmony Analysis

    题目链接:http://codeforces.com/contest/610/problem/C 解题思路: 将后一个矩阵拆分为四个前一状态矩阵,其中三个与前一状态相同,剩下一个直接取反就行.还有很多 ...

  7. Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并

    D. Vika and Segments     Vika has an infinite sheet of squared paper. Initially all squares are whit ...

  8. Codeforces Round #337 (Div. 2) C. Harmony Analysis 数学

    C. Harmony Analysis   The semester is already ending, so Danil made an effort and decided to visit a ...

  9. Codeforces Round #337 (Div. 2) B. Vika and Squares 水题

    B. Vika and Squares   Vika has n jars with paints of distinct colors. All the jars are numbered from ...

随机推荐

  1. MongoDB 3.0(1):CentOS7 安装MongoDB 3.0服务

    目录(?)[-] 1下载安装 2MongoDB CRUD 1创建数据 2更新数据 3删除 4查询 5更多方法 3MongoDB可视化工具 4总结   本文原文连接: http://blog.csdn. ...

  2. 在Eclipse中创建Maven多模块工程的例子

    .配置eclipse的maven .在Eclipse里面New -> Maven Project -> 选择“Create a simple project” Group Id: com. ...

  3. [Usaco2015 Feb]Censoring(bzoj 3942)

    Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...

  4. hdu 1249 三角形

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1249 part=3*s*(s-1)+2 #include<stdio.h> #includ ...

  5. elk安装(这个是初级的可以把这个套件安上)

    http://udn.yyuap.com/doc/logstash-best-practice-cn/index.html ELK其实并不是一款软件,而是一整套解决方案,是三个开源软件Elastics ...

  6. MVA Universal Windows Apps系列学习笔记1

    昨天晚上看了微软的Build 2015大会第一天第一场演讲,时间还挺长,足足3个小时,不过也挺震撼的.里面提到了windows 10.Microsoft edge浏览器.Azure云平台.Office ...

  7. 修改了/etc/fstab之后出现登录密码输入之后又返回登录界面的问题

    最后那一个挂载到/home下面的盘是我新增加的,如果注释掉就一切正常,如果取消注释,就会发生标题说的问题. 后来我意思都这样直接挂载,导致/home下面原本的东西不在了,注释掉之后再来看,发现下面确实 ...

  8. Oracle 创建/删除 表空间、用户、授权

    首先以DBA连接到数据库:sqlplus / as sysdba; --创建表空间 create tablespace test_tablespace datafile 'D:\developer\o ...

  9. js中ascii码的转换

    今天在把原来用C写的程序移植到javascript上,但是有个地方一直调不通,后来才发现是js奇葩的字符处理出的问题.c中使用的字符处理比如加上一个字符值强制转换一下,在js中就行不通了. 但是js提 ...

  10. hdu 4759 大数+找规律 ***

    题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y  问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...