后面的题目补不懂了

暴力 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)的更多相关文章

  1. 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 ( ...

  2. 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 ...

  3. BestCoder Round #11 (Div. 2) 题解

    HDOJ5054 Alice and Bob Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  4. hdu5635 BestCoder Round #74 (div.2)

    LCP Array  Accepts: 131  Submissions: 1352  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 13 ...

  5. hdu 5636 搜索 BestCoder Round #74 (div.2)

    Shortest Path  Accepts: 40  Submissions: 610  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: ...

  6. hdu5634 BestCoder Round #73 (div.1)

    Rikka with Phi  Accepts: 5  Submissions: 66  Time Limit: 16000/8000 MS (Java/Others)  Memory Limit: ...

  7. hdu5631 BestCoder Round #73 (div.2)

    Rikka with Graph  Accepts: 123  Submissions: 525  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  8. hdu5630 BestCoder Round #73 (div.2)

    Rikka with Chess  Accepts: 393  Submissions: 548  Time Limit: 2000/1000 MS (Java/Others)  Memory Lim ...

  9. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

随机推荐

  1. shell之数值运算

    Shell中声明变量默认是字符串, 要参与数值运算,可使用下面方式,简单,表示以数值方式.

  2. C语言中一个替换 strcpy的极好的方法

    在C语言中有个方法:strcpy() 使用时经常容易内存申请不足,或是没有申请内存导致,复制的时候报错,我新写了一个方法,弥补这个缺陷 char *strcpy1(char *strDes, char ...

  3. EF – 问题集锦

    1.对一个或多个实体的验证失败.有关详细信息,请参见“EntityValidationErrors”属性 在EF5.0修改实体的时候,出现“对一个或多个实体的验证失败.有关详细信息,请参见“Entit ...

  4. 无废话Android之listview入门,自定义的数据适配器、采用layoutInflater打气筒创建一个view对象、常用数据适配器ArrayAdapter、SimpleAdapter、使用ContentProvider(内容提供者)共享数据、短信的备份、插入一条记录到系统短信应用(3)

    1.listview入门,自定义的数据适配器 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and ...

  5. java 泛型 -- 泛型类,泛型接口,泛型方法

    泛型T泛型的许多最佳例子都来自集合框架,因为泛型让您在保存在集合中的元素上指定类型约束.在定义泛型类或声明泛型类的变量时,使用尖括号来指定形式类型参数.形式类型参数与实际类型参数之间的关系类似于形式方 ...

  6. Babelfish(二分查找,字符串的处理略有难度,用sscanf输入)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 28581   Accepted: 12326 题目链接: ...

  7. Code Review for SSIS package

    以下是我对SSIS包进行code review的一些建议,如果有其他更好的方案欢迎拍砖. A. 查看是否使用了最优的解决方案 1. 最优的结构视图 2. 解决方案,包,任务,组建,参数的命名使用了易读 ...

  8. 数据结构之图 Part2 - 1

    邻接矩阵 网上很少有C# 写图的数据结构的例子,实际的项目中也从来没用过Array 这坨东西,随手写个,勿喷. namespace LH.GraphConsole { public struct Gr ...

  9. 关于socket——SO_SNDBUF and SO_RECVBUF

    转自:http://blog.csdn.net/wf1982/article/details/38871521 参见 http://stackoverflow.com/questions/425741 ...

  10. 在Salesforce中避免对Trigger中Update的无限循环操作

    在Salesforce中避免对Trigger中Update的无限循环操作: 处理Trigger的时候会有这么一个场景:在Trigger中想修改该Object的某些字段的值,那么如果们在程序中再用代码的 ...