水 A - Kefa and First Steps

/************************************************
* Author :Running_Time
* Created Time :2015/9/23 星期三 00:19:33
* File Name :A.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
int a[N]; int main(void) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
}
int l = 1;
int ans = 1; int pre = a[1];
for (int i=2; i<=n; ++i) {
if (a[i] >= pre) {
pre = a[i]; ans = max (ans, i - l + 1);
}
else {
pre = a[i]; l = i;
}
}
printf ("%d\n", ans); return 0;
}

  

尺取法 B - Kefa and Company

题意:每个朋友有他的金钱和友好程度,从朋友中选取一些人,问在贫富差距小于d的最大友好程度和为多少

分析:先按照m金钱从小到大排序,枚举每个起点看以这个人为最穷的人能得到的最大友好程度多少,然后是第二穷的人。。。。。复杂度O (nlogn),尺取法也叫two points ?

/************************************************
* Author :Running_Time
* Created Time :2015/9/23 星期三 00:19:38
* File Name :B.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
struct Friend {
int m, s;
bool operator < (const Friend &r) const {
return m < r.m;
}
}f[N]; int main(void) {
int n, d, mn = INF, mx = -1;
ll sum = 0;
scanf ("%d%d", &n, &d);
for (int i=1; i<=n; ++i) {
scanf ("%d%d", &f[i].m, &f[i].s);
if (f[i].m > mx) mx = f[i].m;
if (f[i].m < mn) mn = f[i].m;
sum += f[i].s;
}
if (mx - mn < d) {
printf ("%I64d\n", sum); return 0;
}
sort (f+1, f+1+n);
int l = 1, r = 2;
ll ans = f[1].s; sum = f[1].s;
while (true) {
while (r <= n && f[r].m - f[l].m < d) {
sum += f[r++].s;
}
ans = max (ans, sum);
if (r > n) break;
sum -= f[l++].s;
}
printf ("%I64d\n", ans); return 0;
}

  

DFS C - Kefa and Park

题意:从根节点1出发,到底部的点的路径没有超过连续m个点有cat的个数为多少

分析:简单的深搜,记录走到当前点最大连续cat数,注意一些剪枝

/************************************************
* Author :Running_Time
* Created Time :2015/9/23 星期三 00:19:41
* File Name :C.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
vector<int> G[N];
int cat[N];
bool vis[N];
int n, m, ans; void DFS(int u, int fa, int num) {
for (int i=0; i<G[u].size (); ++i) {
int v = G[u][i];
if (vis[v] || v == fa) continue;
if (cat[v]) {
if (num + 1 <= m) { //算上当前点,cat + 1
if (G[v].size () == 1) { //到达底部
vis[v] = true; ans++;
}
else {
vis[v] = true; //未到达底部
DFS (v, u, num + 1);
}
}
else continue; //条件不符,不往下艘
}
else {
if (num <= m) {
if (G[v].size () == 1) {
vis[v] = true; ans++;
}
else {
vis[v] = true;
DFS (v, u, 0);
}
}
else continue;
}
}
} int main(void) {
scanf ("%d%d", &n, &m);
for (int i=1; i<=n; ++i) {
scanf ("%d", &cat[i]);
}
for (int u, v, i=1; i<n; ++i) {
scanf ("%d%d", &u, &v);
G[u].push_back (v);
G[v].push_back (u);
}
DFS (1, 0, cat[1]);
printf ("%d\n", ans); return 0;
}

  

状态压缩DP D - Kefa and Dishes

题意:n道菜选择m道,每道菜有一个愉悦度,如果某些菜按照先后顺序吃还能得到额外的愉悦度,问最大愉悦度为多少

分析:其实就是一个DAG问题,数据范围18应该想到状压,我不熟悉以为数据范围太大,做不了。dp[mask][i] 表示当在mask集合状态下,最后是第i道菜的最大愉悦度为多少,状态转移方程:dp[(i|(1<<l))][l] = max (dp[i][j] + a[l] + g[j][l])  复杂度O(2n * n2).

/************************************************
* Author :Running_Time
* Created Time :2015/9/23 星期三 01:49:58
* File Name :D.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 18;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
int n, m, k;
ll dp[(1<<N)+10][N];
int a[N];
int g[N][N]; int main(void) {
scanf ("%d%d%d", &n, &m, &k);
for (int i=0; i<n; ++i) {
scanf ("%d", &a[i]);
}
for (int u, v, c, i=1; i<=k; ++i) {
scanf ("%d%d%d", &u, &v, &c);
if (g[u-1][v-1] < c) g[u-1][v-1] = c;
}
int maxS = (1 << n);
for (int i=0; i<n; ++i) {
dp[(1<<i)][i] = a[i];
} for (int i=1; i<maxS; ++i) {
for (int j=0; j<n; ++j) {
if ((i & (1 << j)) == 0) continue;
for (int l=0; l<n; ++l) {
if ((i & (1 << l)) == 0) {
if (dp[(i|(1<<l))][l] < dp[i][j] + a[l] + g[j][l]) {
dp[(i|(1<<l))][l] = dp[i][j] + a[l] + g[j][l];
}
}
}
}
}
ll ans = 0;
for (int i=1; i<maxS; ++i) {
int cnt = 0;
for (int j=0; j<n; ++j) {
if ((i & (1 << j)) != 0) cnt++;
}
if (cnt == m) {
for (int j=0; j<n; ++j) {
if ((i & (1 << j)) != 0) {
if (ans < dp[i][j]) ans = dp[i][j];
}
}
}
}
printf ("%I64d\n", ans); return 0;
}

  

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

  1. Codeforces Round #321 (Div. 2) E. Kefa and Watch 线段树hash

    E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/prob ...

  2. Codeforces Round #321 (Div. 2) C. Kefa and Park dfs

    C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...

  3. Codeforces Round #321 (Div. 2) B. Kefa and Company 二分

    B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/pr ...

  4. Codeforces Round #321 (Div. 2) A. Kefa and First Steps 水题

    A. Kefa and First Steps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/58 ...

  5. codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/580/A题意:求最长连续非降子序列的长度.C++代码: #include <iostream ...

  6. Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)

    http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...

  7. 「日常训练」Kefa and Dishes(Codeforces Round #321 Div. 2 D)

    题意与分析(CodeForces 580D) 一个人有\(n\)道菜,然后要点\(m\)道菜,每道菜有一个美味程度:然后给你了很多个关系,表示如果\(x\)刚好在\(y\)前面做的话,他的美味程度就会 ...

  8. 「日常训练」Kefa and Park(Codeforces Round #321 Div. 2 C)

    题意与分析(CodeForces 580C) 给你一棵树,然后每个叶子节点会有一家餐馆:你讨厌猫(waht?怎么会有人讨厌猫),就不会走有连续超过m个节点有猫的路.然后问你最多去几家饭店. 这题我写的 ...

  9. 「日常训练」Kefa and Company(Codeforces Round #321 Div. 2 B)

    题意与分析(CodeForces 580B) \(n\)个人,告诉你\(n\)个人的工资,每个人还有一个权值.现在从这n个人中选出m个人,使得他们的权值之和最大,但是对于选中的人而言,其他被选中的人的 ...

  10. Codeforces Round #321 (Div. 2) Kefa and Dishes 状压+spfa

    原题链接:http://codeforces.com/contest/580/problem/D 题意: 给你一些一个有向图,求不超过m步的情况下,能获得的最大权值和是多少,点不能重复走. 题解: 令 ...

随机推荐

  1. String池与iterator对集合的迭代

    一.静态导入 1.       导入类的静态属性 import static java.lang.System.out; out.println("haha"); 2.       ...

  2. spring MVC (学习笔记)

    web.xml 相关配置 <?xml version="1.0" encoding="UTF-8"?><web-app xmlns=" ...

  3. xamarin.android searchview的一些用法

    前言 searchview是安卓常用的搜索控件,网上有很多关于searchview都是java的,所以我参看xamaroin官网的一些demo总结一些方法. 导读 1.如何创建一个searchview ...

  4. 将线上服务器生成的日志信息实时导入kafka,采用agent和collector分层传输,app的数据通过thrift传给agent,agent通过avro sink将数据发给collector,collector将数据汇集后,发送给kafka

    记flume部署过程中遇到的问题以及解决方法(持续更新) - CSDN博客 https://blog.csdn.net/lijinqi1987/article/details/77449889 现将调 ...

  5. BZOJ3260: 跳

    BZOJ3260: 跳 Description 邪教喜欢在各种各样空间内跳.现在,邪教来到了一个二维平面. 在这个平面内,如果邪教当前跳到了(x,y),那么他下一步可以选择跳到以下4个点: (x-1, ...

  6. opencv VS2010配置

    一.下载 opencv下载地址:http://www.opencv.org.cn/  点击下载栏 最新的可能有3.2了,但是支持的VS版本是VS2012等版本.这里只选用2.4.9版本 下载后就是安装 ...

  7. [翻译]理解Unity的自动内存管理

    当创建对象.字符串或数组时,存储它所需的内存将从称为堆的中央池中分配.当项目不再使用时,它曾经占用的内存可以被回收并用于别的东西.在过去,通常由程序员通过适当的函数调用明确地分配和释放这些堆内存块.如 ...

  8. springboot如何使用外部tomcat容器

    一般情况spring-boot-starter-web是自带tomcat(即springboot内嵌tomcat),所以打包直接生成jar包,用java -jar命令就可以启动. 但,有时我们希望用w ...

  9. How to create a List of ValueTuple?

    ValueTuple需要通过NuGet安装System.ValueTuple https://docs.microsoft.com/en-us/dotnet/csharp/tuples?view=ne ...

  10. Redis使用基本套路

    Redis的数据,通常都是来自于数据库. 存入Redis当中,可以快速的查询.不用每次都关联查询,然后其他处理什么的. 通常可以把一些,不经常变的数据存储其中. 避免数据变动,而Redis缓存数据不变 ...