Codeforces Round #344 (Div. 2)
注意是或不是异或
#include <bits/stdc++.h> int a[1005], b[1005]; int main() {
int n; scanf ("%d", &n);
for (int i=0; i<n; ++i) {
scanf ("%d", a+i);
}
for (int i=0; i<n; ++i) {
scanf ("%d", b+i);
}
int ans = 0;
for (int i=0; i<n; ++i) {
int x = 0, y = 0;
for (int j=i; j<n; ++j) {
x |= a[j]; y |= b[j];
ans = std::max (ans, x + y);
}
}
printf ("%d\n", ans); return 0;
}
color[i][j] = max (timei(rowi), timej(colj)))
#include <bits/stdc++.h> const int N = 5e3 + 5;
int a[N][N];
std::pair<int, int> row[N], col[N]; int main() {
int n, m, k; scanf ("%d%d%d", &n, &m, &k);
for (int op, x, y, i=1; i<=k; ++i) {
scanf ("%d%d%d", &op, &x, &y);
if (op == 1) {
row[x] = std::make_pair (y, i);
} else {
col[x] = std::make_pair (y, i);
}
}
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) {
int tr = row[i].second, tc = col[j].second;
if (tr > tc && tr > 0) {
a[i][j] = row[i].first;
} else if (tc > tr && tc > 0) {
a[i][j] = col[j].first;
}
}
}
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) {
printf ("%d%c", a[i][j], j == m ? '\n' : ' ');
}
} return 0;
}
单调队列+排序 C - Report
题意:给m次操作,每次操作使得[1, r]范围的的a[i]升序或降序排序,问a[i]最后的结果
分析:因为左端点固定,右端点远的且操作时间靠后的可以覆盖之前右端点近的操作,所以先从右端点最远且时间靠后的时间出发,之后类似只要处理右端点降序的位置,即维护一个单调队列。队列中后一次操作长度不大于前一次长度,减少的长度k里的数字为前一次范围中前k大的数或前k小的数。
#include <bits/stdc++.h> const int N = 2e5 + 5;
int a[N], b[N];
int r[N], t[N]; int main() {
int n, m; scanf ("%d%d", &n, &m);
for (int i=1; i<=n; ++i) {
scanf ("%d", a+i);
}
int s = 0;
for (int x, y, i=1; i<=m; ++i) {
scanf ("%d%d", &x, &y);
while (s > 0 && y >= r[s-1]) s--;
t[s] = x; r[s] = y; s++;
}
r[s++] = 0; int bl = 1, br = r[0];
for (int i=bl; i<=br; ++i) b[i] = a[i];
std::sort (b+1, b+1+br); for (int i=1; i<s; ++i) {
for (int j=r[i-1]; j>r[i]; --j) {
a[j] = (t[i-1] == 1) ? b[br--] : b[bl++];
}
} for (int i=1; i<=n; ++i) {
printf ("%d ", a[i]);
}
puts (""); return 0;
}
KMP D - Messenger
题意:给两个字符串,问后者在前者里出现的次数。给出的方式:1-a 2-b 3-c 4-d(abbcccddd)
分析:其实想明白就知道这就是简单的KMP问题,文本串第一个和最后一个的个数一定要比模式串多,且里面的要完全相等。还要考虑特殊情况,压缩后m==1或2时。
#include <bits/stdc++.h> typedef long long ll;
const int N = 2e5 + 5;
struct Part {
ll len; char ch;
bool operator == (const Part &rhs) const {
return len == rhs.len && ch == rhs.ch;
}
bool operator >= (const Part &rhs) const {
return len >= rhs.len && ch == rhs.ch;
}
bool operator != (const Part &rhs) const {
return len != rhs.len || ch != rhs.ch;
}
};
Part A[N], B[N];
int fail[N]; int compress(Part *C, int n) {
int m = 0;
for (int i=1; i<n; ++i) {
if (C[m].ch == C[i].ch) {
C[m].len += C[i].len;
} else {
C[++m] = C[i];
}
}
return m + 1;
} void get_fail(Part *P, int lenp) {
int i = 0, j = -1; fail[0] = -1;
while (i < lenp) {
if (j == -1 || P[j] == P[i]) {
++i; ++j; fail[i] = j;
} else {
j = fail[j];
}
}
} ll KMP(Part *C, int n, Part *D, int m) {
get_fail (D, m);
int i = 0, j = 0;
ll ret = 0;
while (i < n) {
while (j != -1 && C[i] != D[j]) j = fail[j];
i++; j++;
if (j == m) {
if (C[i] >= D[m] && C[i-m-1] >= D[-1]) ret++;
j = fail[j];
}
}
return ret;
} int main() {
int n, m; scanf ("%d%d", &n, &m);
int bug = 0;
char str[3];
for (int i=0; i<n; ++i) {
scanf ("%I64d-%s", &A[i].len, str);
A[i].ch = str[0];
}
for (int i=0; i<m; ++i) {
scanf ("%I64d-%s", &B[i].len, str);
B[i].ch = str[0];
}
n = compress (A, n);
m = compress (B, m);
ll ans = 0;
if (m == 1) {
for (int i=0; i<n; ++i) {
if (A[i].ch == B[0].ch) {
ans += std::max (0ll, A[i].len - B[0].len + 1);
}
}
} else if (m == 2) {
for (int i=0; i<n-1; ++i) {
if (A[i] >= B[0] && A[i+1] >= B[1]) ans++;
}
} else {
ans = KMP (A+1, n-2, B+1, m-2);
}
printf ("%I64d\n", ans); return 0;
}
题意:将一个点移动到另一个点(可相同),求
分析:推算化简的得到:
或者
先考虑后者,再次化简得到:,,可以抽象成ax+b, (x = ar),所以我们枚举ar,得到最大的,用到了凸包,把直线加入凸包,得到单调上升的类似于这样的,然后二分找最大值。前者类似。
第一次碰到这种题,写详细点:)
#include <bits/stdc++.h> typedef long long ll;
const int N = 2e5 + 5;
int a[N];
ll sum[N]; struct Line {
int a; ll b;
ll get(int x) {
return 1ll * a * x + b;
}
};
struct Convex_hull {
int sz;
Line *hull;
Convex_hull(int maxn) {
hull = new Line[++maxn]; sz = 0;
}
void clear() {
sz = 0;
}
bool is_bad(int cur, int pre, int nex) {
Line c = hull[cur], p = hull[pre], n = hull[nex];
return (c.b - n.b) * (c.a - p.a) <= (p.b - c.b) * (n.a - c.a);
}
void add_line(int a, ll b) {
hull[sz++] = (Line) {a, b};
while (sz > 2 && is_bad (sz-2, sz-3, sz-1)) {
hull[sz-2] = hull[sz-1]; sz--;
}
}
ll query(int x) {
int low = -1, high = sz - 1;
while (low + 1 < high) {
int mid = low + high >> 1;
if (hull[mid].get (x) <= hull[mid+1].get (x)) {
low = mid;
} else {
high = mid;
}
}
return hull[high].get (x);
}
}; int main() {
int n; scanf ("%d", &n);
ll ans = 0; sum[0] = 0;
for (int i=1; i<=n; ++i) {
scanf ("%d", a+i);
sum[i] = sum[i-1] + a[i];
ans += 1ll * a[i] * i;
}
Convex_hull *hull = new Convex_hull (n);
ll add = 0;
for (int r=2; r<=n; ++r) {
hull->add_line (r-1, -sum[r-2]);
add = std::max (add, hull->query (a[r]) + sum[r-1] - 1ll * a[r] * r);
}
hull->clear ();
for (int l=n-1; l>=1; --l) {
hull->add_line (-(l+1), -sum[l+1]);
add = std::max (add, hull->query (-a[l]) + sum[l] - 1ll * a[l] * l);
}
printf ("%I64d\n", ans + add); return 0;
}
Codeforces Round #344 (Div. 2)的更多相关文章
- Codeforces Round #344 (Div. 2) A. Interview
//http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...
- Codeforces Round #344 (Div. 2) A
A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳
E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...
- Codeforces Round #344 (Div. 2) D. Messenger kmp
D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...
- Codeforces Round #344 (Div. 2) C. Report 其他
C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...
- Codeforces Round #344 (Div. 2) B. Print Check 水题
B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...
- Codeforces Round #344 (Div. 2) A. Interview 水题
A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...
- Codeforces Round #344 (Div. 2) B. Print Check
B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #344 (Div. 2)(按位或运算)
Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...
随机推荐
- IntelliJ IDEA 15.0.4常用快捷键整理
一.背景 最近刚转了IDEA,感觉真是爽的一逼,太智能了,回不去Eclipse了,还有些淡淡的忧伤呢~在使用中很多的快捷键帮了开发的大忙,让我可以达到事半功倍的效果,下面就罗列出来,与大家共同分享. ...
- [Android Pro] Test win
http://www.cnblogs.com/mayingbao/ http://www.cnblogs.com/hyddd/
- gcc提供的原子操作函数
gcc从4.1.2提供了__sync_*系列的built-in函数,用于提供加减和逻辑运算的原子操作.其声明如下: type __sync_fetch_and_add (type *ptr, type ...
- solrconfig.xml和schema.xml说明
1. solrconfig.xml solrconfig.xml配置文件主要定义了SOLR的一些处理规则,包括索引数据的存放位置,更新,删除,查询的一些规则配置. 1.1. datadir节点 ...
- nfs server的配置 Starting NFS daemon: [FAILED]
总结了一下是nfs server的制作过程:nfs(Network File System)其实就是说,这个机器的硬盘不够了,我要把文件放到别的服务器上去,服务器端的配置如下:首先(1)确保你的机器上 ...
- DB2 create partitioned table
在Z上和开放平台上的创建方法还不太一样,两套人马开发出来的就是牛! 蛋疼…… 贴不同类型的几个例子感受一下,Z上的ASC,DESC不见了: CREATE TABLE foo(a INT) PARTIT ...
- Stuts2的"struts.devMode"设置成true后,不起作用,仍需要重启tomcat
在项目的struts.xml加入了常量配置:<constant name="struts.devMode" value="true" />后,重启服 ...
- CLR via C#(13)-浅谈事件
提起事件,我们都不陌生,事件使类之间有了交互的能力.它是建立在委托基础上的.有了前面对委托的了解,相信读起事件来也不会太难了.关于事件,现成的好文章数不胜数,本不打算写了.不过问道有先后,各抒己见,也 ...
- vim: vs sp 调整窗口高度和宽度
转自:http://www.cnblogs.com/xuechao/archive/2011/03/29/1999292.html vim多窗口有时候需要调整默认的窗口宽度和高度,可以用如下命令配合使 ...
- HTTP中302与301的区别以及在ASP.NET中如何实现
一.官方说法301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于: 301 redirect: 301 代表永久性转移(Permanently Moved).302 re ...