BestCoder Round #72 (div.2)
后面的题目补不懂了
暴力 1001 Clarke and chemistry
这题也把我搞死了。。枚举系数判断就行了
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map> int cnt[3][30]; bool error(void) {
for (int i=0; i<2; ++i) {
for (int j=0; j<26; ++j) {
if (cnt[i][j] != -1 && cnt[2][j] == -1) {
return true;
}
}
}
return false;
} int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int A, B, C; scanf ("%d%d%d", &A, &B, &C);
memset (cnt, -1, sizeof (cnt));
char c[2]; int t;
for (int i=0; i<A; ++i) {
scanf ("%s %d", &c, &t);
cnt[0][c[0]-'A'] = t;
}
for (int i=0; i<B; ++i) {
scanf ("%s %d", &c, &t);
cnt[1][c[0]-'A'] = t;
}
for (int i=0; i<C; ++i) {
scanf ("%s %d", &c, &t);
cnt[2][c[0]-'A'] = t;
}
bool flag = true;
int ans1 = 1000000, ans2 = 1000000;
for (int i=1; i<=2000&&flag; ++i) {
for (int j=1; j<=2000&&flag; ++j) {
bool ok = true;
for (int k=0; k<26; ++k) {
if (cnt[2][k] == -1) continue;
if (cnt[0][k] == -1 && cnt[1][k] == -1) {
flag = false; break;
}
int x = 0;
if (cnt[0][k] != -1) x = cnt[0][k] * i;
if (cnt[1][k] != -1) x += cnt[1][k] * j;
if (x != cnt[2][k]) {
ok = false; break;
}
}
if (ok) {
if (i < ans1 || (i == ans1 && j < ans2)) ans1 = i, ans2 = j;
}
}
}
if (error ()) flag = false;
if (flag && ans1 < 1000000) printf ("%d %d\n", ans1, ans2);
else puts ("NO");
} return 0;
}
数学 1002 Clarke and points
题意: 求|XA - XB| + |YA - YB| 最大
分析:去掉绝对值,就知道只要得到最大最小的(XA + XB) 和 (XA - XB)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
using namespace std; long long seed;
inline long long rand(long long l, long long r) {
static long long mo=1e9+7, g=78125;
return l+((seed*=g)%=mo)%(r-l+1);
} const int N = 1e6 + 5;
pair<long long, long long> p[N];
long long mx[2], mn[2]; int main(void) {
int T; cin >> T;
while (T--) {
int n;
cin >> n >> seed;
mx[0] = mx[1] = -(1ll << 60);
mn[0] = mn[1] = (1ll << 60);
for (int i = 0; i < n; i++) {
p[i].first = rand (-1000000000, 1000000000);
p[i].second = rand (-1000000000, 1000000000);
mx[0] = max (mx[0], p[i].first + p[i].second);
mx[1] = max (mx[1], p[i].first - p[i].second);
mn[0] = min (mn[0], p[i].first + p[i].second);
mn[1] = min (mn[1], p[i].first - p[i].second);
}
cout << max (abs (mx[0] - mn[0]), abs (mx[1] - mn[1])) << '\n';
}
return 0;
}
贪心 + BFS Clarke and MST
题意:求位运算and的最大生成树
分析:枚举数字每一位是否有可能为1,即(now & w == now),用BFS遍历所有生成树
#include <cstdio>
#include <cstring>
#include <queue> const int N = 3e5 + 5;
struct Edge {
int v, w;
};
std::vector<Edge> G[N]; int n, m;
bool vis[N]; bool BFS(int now) {
std::queue<int> que;
memset (vis, false, sizeof (vis));
que.push (1); vis[1] = true;
while (!que.empty ()) {
int u = que.front (); que.pop ();
for (int i=0; i<G[u].size (); ++i) {
int v = G[u][i].v;
int w = G[u][i].w;
if (!vis[v] && (w & now) == now) {
vis[v] = true;
que.push (v);
}
}
}
for (int i=1; i<=n; ++i) if (!vis[i]) return false;
return true;
} int main(void) {
int T; scanf ("%d", &T);
while (T--) {
scanf ("%d%d", &n, &m);
for (int i=0; i<=n; ++i) G[i].clear ();
for (int u, v, w, i=0; i<m; ++i) {
scanf ("%d%d%d", &u, &v, &w);
G[u].push_back ((Edge) {v, w});
G[v].push_back ((Edge) {v, w});
}
int ans = 0;
for (int i=30; i>=0; --i) {
int now = ((1 << i) | ans);
if (BFS (now)) ans = now;
}
printf ("%d\n", ans);
} return 0;
}
BestCoder Round #72 (div.2)的更多相关文章
- BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)
Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- BestCoder Round #68 (div.2) tree(hdu 5606)
tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- BestCoder Round #11 (Div. 2) 题解
HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- hdu5635 BestCoder Round #74 (div.2)
LCP Array Accepts: 131 Submissions: 1352 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- hdu5634 BestCoder Round #73 (div.1)
Rikka with Phi Accepts: 5 Submissions: 66 Time Limit: 16000/8000 MS (Java/Others) Memory Limit: ...
- hdu5631 BestCoder Round #73 (div.2)
Rikka with Graph Accepts: 123 Submissions: 525 Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- hdu5630 BestCoder Round #73 (div.2)
Rikka with Chess Accepts: 393 Submissions: 548 Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
随机推荐
- SQL如何本地数据库连接服务器的数据库
当我们本地数据库的数据作为测试的时候,需要服务器上的数据,但是每次都远程服务器打开数据库查看数据是很麻烦的,那么我们如何让本地的数据库连接服务器上的数据库.前提是你本地的数据库的版本必须和服务器上的数 ...
- lazyload
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- CentOS yum的详细使用方法
yum是什么yum = Yellow dog Updater, Modified主要功能是更方便的添加/删除/更新RPM包.它能自动解决包的倚赖性问题.它能便于管理大量系统的更新问题yum特点可以同时 ...
- 解决eclipse中maven web工程打包成war(发布到tomcar)时lib中没有jar包的解决方法
可能有两个原因:1.maven中某些jar包下载不下来 从其他地方下载jar文件放到相应maven本地库的.m2里2..classpath文件中缺少(下面代码的作用是制定maven的jar发布路径)& ...
- 我的JavaEE学习路线图
从学习Java开发到现在虽然也已经快三年了,但是要说到分享一下经验实在是不敢当.权当是对自己的一个总结吧,希望大家不吝指教,互相交流. 照旧,还是现来整理一下我学习Java的一个路线图吧,然后按照这个 ...
- Error parsing 'file:///media/RHEL_5.5\\ x86_64\\ DVD/Server'
Error parsing 'file:///media/RHEL_5.5\\ x86_64\\ DVD/Server' http://lindows.iteye.com/blog/456637 ht ...
- html 中几次方,平方米,立方米,下标,上标,删除线等的表示方法
html 中几次方,平方米,立方米,上标,下标,删除线等的表示方法 上标下标删除线 小号字 M2 54 X24+Y1<3=100 NN <sup>上标</sup> &l ...
- 【JAVA 文件概述】
一.概述 使用此类的原因: 该类将文件或者文件夹封装成对象.方便对文件与文件夹的属性信息进行操作.File对象作为参数传递给流的构造函数.要求:使用File类的常用方法. windows平台下,目录分 ...
- UDP通讯程序设计
UDP通讯程序设计 一.函数化 1.1服务器使用的函数 创建socket----->socket 绑定地址-------->bind 接受数据-------->recvfrom 发送 ...
- Poisson Image Editing
说起泊松,可以顺便提及一下泊松同学的老师,拉普拉斯.学图像或是信号的,一定对拉普拉斯算子和拉普拉斯卷积很熟悉.在泊松图像融合出现之前,也有一种叫Laplacian pyramid blending的融 ...