后面的题目补不懂了

暴力 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. Java自定义注解开发

    一.背景 最近在自己搞一个项目时,遇到可需要开发自定义注解的需求,对于没有怎么关注这些java新特性的来说,比较尴尬,索性就拿出一些时间,来进行研究下自定义注解开发的步骤以及使用方式.今天在这里记下, ...

  2. python eval和literal_eval

    eval是python中一个相当智能的函数,把参数当成表达式,进行最大限度的解析, 比如: a = "[[1,2], [3,4], [5,6], [7,8], [9,0]]" b ...

  3. js判断是否为ie6以外的浏览器,若是,则调用相应脚本

    if(navigator.userAgent.indexOf("MSIE 6.0") < 0) { //相应JavaScript脚本}

  4. ios添加百度地图方法

    Hello BaiduMapiOS SDK 引入头文件 引入静态库文件 引入系统framework 引入mapapi.bundle资源文件 初始化BMKMapManager 创建BMKMapView ...

  5. 《Thinking in Java》十四章类型信息_习题解

    1~10    Page 318 练习1. 在ToyTest.java中,将Toy的默认构造器注释掉,并解释发生的现象. 书中代码如下(略有改动): package org.cc.foo_008; p ...

  6. poj 1837

    题目链接:http://poj.org/problem?id=1837 题目大意: 有一个天平,左臂右臂各长15,然后给出n,m,n代表有几个挂钩,挂钩给出负数代表在左臂的距离,正数则在右臂m代表有m ...

  7. max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

    在/etc/syscurity/limits.conf 加入以下两行: elastic hard nofile 65536 elastic soft nofile  65536 #备注:elastic ...

  8. MVC - 11(下)jquery.tmpl.js +ajax分页

    继续 mvc-11(上).dto:http://www.cnblogs.com/tangge/p/3840060.html jquery.tmpl.js 下载:http://pan.baidu.com ...

  9. android:id="@id/resid" , andorid:id="@+id/resid" 的区别

    的区别?android:id="@id/resid"    // 引用现有的资源idandorid:id="@+id/resid"  // 新增一个资源id i ...

  10. Chrome Crx 插件下载

    扯蛋的GFW屏蔽了google域导致下载Chrome插件加载失败,本人想收集以些chrome的Crx插件,可供直接下载 XMarks - 在不同电脑不同浏览器之间同步书签 下载地址:   http:/ ...