牛客国庆集训派对Day7 Solution
A Relic Discovery
水。
#include <bits/stdc++.h>
using namespace std; int t, n; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%d", &n);
int res = ;
for (int i = , a, b; i <= n; ++i)
{
scanf("%d%d", &a, &b);
res += a * b;
}
printf("%d\n", res);
}
return ;
}
B Pocket Cube
按题意模拟即可,注意顺时针转逆时针转均可,也就是说一个面有八种旋转可能
#include <bits/stdc++.h>
using namespace std; int t;
int G[][], tmp[][]; bool ok()
{
for (int i = ; i <= ; ++i)
for (int j = ; j <= ; ++j)
if (tmp[i][j] != tmp[i][j - ])
return false;
return true;
} void clear()
{
for (int i = ; i <= ; ++i)
for (int j = ; j <= ; ++j)
tmp[i][j] = G[i][j];
} int origin[][][] =
{
// top
{, , , , , , , , , , , , , , , ,},
// bottom
{, , , , , , , , , , , , , , , ,},
// left
{, , , , , , , , , , , , , , , ,},
// right
{, , , , , , , , , , , , , , , ,},
// front
{, , , , , , , , , , , , , , , ,},
// back
{, , , , , , , , , , , , , , , ,},
}; int Move[][][] =
{
{, , , , , , , , , , , , , , , ,},
{, , , , , , , , , , , , , , , ,},
{, , , , , , , , , , , , , , , ,},
{, , , , , , , , , , , , , , , ,},
{, , , , , , , , , , , , , , , ,},
{, , , , , , , , , , , , , , , ,},
}; bool work()
{
clear(); if (ok()) return true;
for (int i = ; i < ; ++i)
{
for (int j = ; j < ; j += )
{
clear();
for (int k = ; k < ; ++k)
{
int x = (j + k) % ;
tmp[origin[i][x][]][origin[i][x][]] = G[Move[i][x][]][Move[i][x][]];
}
if (ok()) return true;
}
for (int j = ; j < ; j += )
{
clear();
for (int k = ; k > -; --k)
{
int x = (j + k + ) % ;
int y = (x + ) % ;
tmp[origin[i][x][]][origin[i][x][]] = G[Move[i][y][]][Move[i][y][]];
}
if (ok()) return true;
}
}
return false;
} int main()
{
scanf("%d", &t);
while(t--)
{
for (int i = ; i <= ; ++i)
for (int j = ; j <= ; ++j)
scanf("%d", &G[i][j]);
puts(work() ? "YES" : "NO");
}
return ;
}
C Pocky
根据样例发现规律 答案为 log(l / d) + 1.0 如果 l <= d 答案为0
#include <bits/stdc++.h>
using namespace std; const double eps = 1e-; int t;
double l, d; int main()
{
scanf("%d", &t);
while (t--)
{
scanf("%lf%lf", &l, &d);
if (l <= d || fabs(l - d) <= eps)
printf("%.6f\n", 0.0);
else
printf("%.6f\n", log(l / d) + 1.0);
}
return ;
}
D Lucky Coins
留坑。
E Fibonacci
留坑。
F Lambda Calculus
留坑。
G Coding Contest
题意:有n个区域,每个区域有$s_i$个人以及$b_i$个食物,有m条路,每条路最多让$c_i$个人走,其中第一个人走不产生影响,后面的每个人都有p的可能破坏 求最小的破坏可能
思路:将p取log就变成了累加最小,建立一个源点以及一个汇点,其中每块区域需要出走的人和汇点相连,可以进来的人与源点相连,跑一遍最小费用最大流即可
#include<bits/stdc++.h> using namespace std; const double eps = 1e-;
const double EI = exp(1.0);
const int maxn = ;
const int maxm = ;
const int INF = 0x3f3f3f3f; int sgn(double x)
{
if(fabs(x) < eps) return ;
else return x > ? : -;
} struct Edge{
int to, nxt, cap, flow;
double cost;
}edge[maxm]; double ans;
int head[maxn], tot;
int pre[maxn];
double dis[maxn];
bool vis[maxn];
int N; void Init(int n)
{
N = n;
tot = ;
for(int i = ; i <= n; ++i) head[i] = -;
} void addedge(int u, int v,int cap, double cost)
{
edge[tot].to = v;
edge[tot].cap = cap;
edge[tot].cost = cost;
edge[tot].flow = ;
edge[tot].nxt = head[u];
head[u] = tot++; edge[tot].to = u;
edge[tot].cap = ;
edge[tot].cost = -cost;
edge[tot].flow = ;
edge[tot].nxt = head[v];
head[v] = tot++;
} bool SPFA(int s,int t)
{
queue<int>q;
for(int i = ; i < N; ++i)
{
dis[i] = INF;
vis[i] = false;
pre[i] = -;
}
dis[s] = ;
vis[s] = true;
q.push(s);
while(!q.empty())
{
int u = q.front();
q.pop();
vis[u] = false;
for(int i = head[u]; ~i; i = edge[i].nxt)
{
int v = edge[i].to;
if(edge[i].cap > edge[i].flow && sgn(dis[v] - dis[u] - edge[i].cost) > )
{
dis[v] = dis[u] + edge[i].cost;
pre[v] = i;
if(!vis[v])
{
vis[v] = true;
q.push(v);
}
}
}
}
if(pre[t] == -) return false;
else return true;
} int minCostMaxflow(int s, int t)
{
int flow = ;
ans = ;
while(SPFA(s, t))
{
int Min = INF;
for(int i = pre[t]; ~i; i = pre[edge[i ^ ].to])
{
Min = min(Min, edge[i].cap - edge[i].flow);
}
for(int i = pre[t]; ~i; i = pre[edge[i ^ ].to])
{
edge[i].flow += Min;
edge[i ^ ].flow -= Min;
ans += edge[i].cost * Min;
}
flow += Min;
}
return flow;
} int n, m;
int s[maxn], b[maxn], tmp[maxn]; int main()
{
int t;
scanf("%d", &t);
while(t--)
{
scanf("%d %d", &n, &m);
Init(n + );
for(int i = ; i <= n; ++i)
{
scanf("%d %d", s + i, b + i);
if(s[i] - b[i] > ) addedge(, i, s[i] - b[i], );
if(s[i] - b[i] < ) addedge(i, n + , b[i] - s[i], );
} for(int i = ; i <= m; ++i)
{
int u, v, c;
double p;
scanf("%d %d %d %lf", &u, &v, &c ,&p);
p = -log(1.0 - p);
if(c > ) addedge(u, v, , );
if(c > ) addedge(u, v, c - , p);
}
int flow = minCostMaxflow(, n + );
ans = pow(EI, -ans);
printf("%.2f\n", 1.0 - ans);
}
return ;
}
H Pattern
留坑。
I Travel Brochure
留坑。
J Cliques
留坑。
K Finding Hotels
题意:有若干酒店,以及一些旅客,每个旅客有价格接受范围,对于每个旅客要找出可接受价格以内的所有酒店中最近的
思路:KDTree 对于价格直接特判,如果超出,直接return INF 还要注意多解的情况下取id小的
#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 200010
#define DIM 10
#define INF 0x3f3f3f3f3f3f3f3f
inline ll sqr(ll x) { return x * x; }
namespace KD
{
int K;
struct Point
{
ll x[DIM];
int id;
ll distance(const Point &b) const
{
if (x[] < b.x[]) return INF;
ll ret = ;
for (int i = ; i < K; ++i) ret += sqr(x[i] - b.x[i]);
return ret;
}
void input(int id) { this->id = id; for (int i = ; i < K + ; ++i) scanf("%lld", x + i); }
void output() { for (int i = ; i < K + ; ++i) printf("%lld%c", x[i], " \n"[i == K]); }
};
struct cmpx
{
int div;
cmpx(const int &div) { this->div = div; }
bool operator () (const Point &a, const Point &b)
{
for (int i = ; i < K; ++i) if (a.x[(div + i) % K] != b.x[(div + i) % K])
return a.x[(div + i) % K] < b.x[(div + i) % K];
return true;
}
};
bool cmp(const Point &a, const Point &b, int div) { return cmpx(div)(a, b); }
struct node
{
Point e;
node *lc, *rc;
int div;
}pool[N], *tail, *root;
void init() { tail = pool; }
node* build(Point *a, int l, int r, int div)
{
if (l >= r) return NULL;
node *p = tail++;
p->div = div;
int mid = (l + r) >> ;
nth_element(a + l, a + mid, a + r, cmpx(div));
p->e = a[mid];
p->lc = build(a, l, mid, (div + ) % K);
p->rc = build(a, mid + , r, (div + ) % K);
return p;
}
Point res; ll Min;
void search(Point p, node *x, int div)
{
if (!x) return;
if (cmp(p, x->e, div))
{
search(p, x->lc, (div + ) % K);
ll tmp = p.distance(x->e);
if (tmp < Min || tmp == Min && x->e.id < res.id)
{
Min = tmp;
res = x->e;
}
if (sqr(x->e.x[div] - p.x[div]) <= Min)
search(p, x->rc, (div + ) % K);
}
else
{
search(p, x->rc, (div + ) % K);
ll tmp = p.distance(x->e);
if (tmp < Min || tmp == Min && x->e.id < res.id)
{
Min = tmp;
res = x->e;
}
if (sqr(x->e.x[div] - p.x[div]) <= Min)
search(p, x->lc, (div + ) % K);
}
}
void search(Point p)
{
Min = INF;
search(p, root, );
}
} int t, n, q;
KD::Point p[N]; void Run()
{
for (scanf("%d", &t); t--; )
{
KD::K = ;
scanf("%d%d", &n, &q);
for (int i = ; i < n; ++i) p[i].input(i);
KD::init();
KD::root = KD::build(p, , n, );
for (int i = ; i <= q; ++i)
{
KD::Point o; o.input();
KD::search(o);
KD::res.output();
}
}
} int main()
{
#ifdef LOCAL
freopen("Test.in", "r", stdin);
#endif Run();
return ; }
L Tower Attack
留坑。
M Generator and Monitor
留坑。
牛客国庆集训派对Day7 Solution的更多相关文章
- 牛客国庆集训派对Day2 Solution
A 矩阵乘法 思路: 1° 牛客机器太快了,暴力能过. #include <bits/stdc++.h> using namespace std; #define N 5000 in ...
- 计算几何板子题【2019牛客国庆集训派对day7——三角形和矩形】【多边形相交的面积】
链接:https://ac.nowcoder.com/acm/contest/1112/J来源:牛客网 题目描述 Bobo 有一个三角形和一个矩形,他想求他们交的面积. 具体地,三角形和矩形由 8 个 ...
- 2019牛客国庆集训派对day7 A 2016
链接:https://ac.nowcoder.com/acm/problem/52800来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...
- 牛客国庆集训派对Day4 Solution
A 深度学习 puts(n) #include <bits/stdc++.h> using namespace std; int main() { double n; while ( ...
- 牛客国庆集训派对Day1 Solution
A Tobaku Mokushiroku Kaiji 水. #include <bits/stdc++.h> using namespace std; ], b[]; void Ru ...
- 牛客国庆集训派对Day3 Solution
A Knight 留坑. B Tree 思路:两次树形DP,但是要考虑0没有逆元 可以用前缀后缀做 #include <bits/stdc++.h> using namespa ...
- 牛客国庆集训派对Day5 Solution
A 璀璨光滑 留坑. B 电音之王 蒙特马利大数乘模运算 #include <bits/stdc++.h> using namespace std; typedef long ...
- 牛客国庆集训派对Day6 Solution
A Birthday 思路:设置一个源点,一个汇点,每次对$源点对a_i, b_i , a_i 对 b_i 连一条流为1,费用为0的边$ 每个点都再连一条 1, 3, 5, 7, ....的边到 ...
- 牛客国庆集训派对Day6 A Birthday 费用流
牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...
随机推荐
- 打开Linux ftp服务,如:vsftpd: unrecognized service
打开Linux ftp服务,如:vsftpd: unrecognized service [root@BZXXDBS02 ~]# service vsftpd start vsftpd: unre ...
- Android App签名打包 与 SDK开发文档
Android App签名打包签名的意义1.为了保证每个程序开发者的合法权益2.放置部分人通过使用相同的Package Name来混淆替换已经安装的程序,从而出现一些恶意篡改3.保证我们每次发布的版本 ...
- Apktool源码解析——第一篇
著名的apktool是android逆向界用的最普遍的一个工具,这个项目的原始地址在这里http://code.google.com/p/android-apktool/,但是你们都懂的在天朝谷歌是无 ...
- LeetCode——Integer to Roman
Description: Given an integer, convert it to a roman numeral. Input is guaranteed to be within the r ...
- 条件注释判断IE浏览器版本
lt,lte,gt,gte分别表示什么 lt:小于当前版本 lte:小于或等于当前版本,包括本身 gt:大于当前版本 gte:大于或等于当前版本,包括本身 使用格式 // 如IE9以下(不包括IE9加 ...
- android 软键盘回车键捕获
EditText editText2 = (EditText)findViewById(R.id.txtTest2); editText2.setOnEditorActionListener(new ...
- Extjs4常见的调试问题
Extjs4常见的调试问题: 1.fireFn.apply of undefined方法名称对不上 2.新增页面居左解决:页面的宽度和高度需要调整,内容items有问题:或者:layout : 'co ...
- onethink重新安装后,还原数据库后,登陆不了解决办法!
在用onethink开发的时候,为了防止修改出错,我会在开发下一个功能的对上一个功能代码整体进行备份,如果出错就返回上一个版本再次修改. 但是会发现一个问题,如果如果返回到上一个版本,重新安装完成之后 ...
- R的替换sub和gsub
sub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, fixed = FALSE, useBytes = FALSE) gsu ...
- POI各Jar包的作用(转)
目前POI的最新发布版本是3.10_FINAL.该版本保护的jar包有: Maven artifactId Prerequisites JAR poi commons-logging, commons ...