2013编程之美资格赛结束,新手上路,收藏no.1认真学习(from mochavic)
2013-04-12 11:44
465 查看
#include <stdio.h> #include <iostream> #include <algorithm> using namespace std; long long f(long long x){ return x * (x - 1) / 2; } int main(){ long long ans = 0; int T, n, m, k, ri = 1, x, y, z; scanf("%d", &T); while (T--){ scanf("%d%d%d", &n, &m, &k); ans = 0; for (x = 1; x <= n; x++){ y = k / x; z = k % x; if (y + (z?1:0) > m) continue; ans = max(f(x) * f(y) + y * f(z), ans); } for (x = 1; x <= m; x++){ y = k / x; z = k % x; if (y + (z?1:0) > n) continue; ans = max(f(x) * f(y) + y * f(z), ans); } cout << "Case #" << ri++ << ": " << ans << endl; } return 0; }
#include <stdio.h> #include <vector> #include <algorithm> using namespace std; int deep[100010], f[100010][2]; vector<int> e[100010]; int c[60], cn; void dfs(int fa, int x, int d){ int i, y; deep[x] = d; for (i = 0; i < (int)e[x].size(); i += 2){ y = e[x][i]; if (y == fa) continue; f[y][0] = x; f[y][1] = e[x][i + 1]; dfs(x, y, d + 1); } } void pd(int x, int y){ while (deep[x] > deep[y]){ c[cn++] = f[x][1]; x = f[x][0]; if (cn == 50) return; } while (deep[y] > deep[x]){ c[cn++] = f[y][1]; y = f[y][0]; if (cn == 50) return; } while (x != y){ c[cn++] = f[x][1]; x = f[x][0]; c[cn++] = f[y][1]; y = f[y][0]; if (cn >= 50) return; } } int main(){ int T, ri = 1, n, m, x, y, z, i; scanf("%d", &T); while (T--){ scanf("%d", &n); for (i = 1; i <= n; i++) e[i].clear(); for (i = 1; i < n; i++){ scanf("%d%d%d", &x, &y, &z); e[x].push_back(y); e[x].push_back(z); e[y].push_back(x); e[y].push_back(z); } dfs(0, 1, 0); printf("Case #%d:n", ri++); scanf("%d", &m); while (m--){ scanf("%d%d", &x, &y); cn = 0; pd(x, y); sort(c, c + cn); for (i = 0; i + 2 < cn; i++){ if (c[i] + c[i + 1] > c[i + 2]) break; } if (i + 2 < cn) printf("Yesn"); else printf("Non"); } } return 0; }
相关文章推荐
- OpenCV新手学习之路(一):环境的搭建(Win8.1 + VS2013 + OpenCV 2.4.8)
- 新手上路学习配置C,C++,GTK等开发环境
- 汇编学习之新手上路1+2+3+……+100
- 2013 编程之美资格赛
- 2013 微软编程之美全国挑战赛之资格赛 传话游戏
- 一连浪了好几天了,一直没好好的学习,希望在运动会结束后能够好好的认真学习,下面是关于栈的链表形式的有关函数的实现,与上一个实现形式有所差别
- 编程之美2013 初赛一 A - 竞价 学习大牛的思路
- 新手上路学习配置C,C++,GTK等开发环境
- 编程之美2013 ---- 资格赛
- 2013编程之美资格赛【传话游戏】
- Oracle学习计划 分类: H2_ORACLE 2013-02-04 14:04 393人阅读 评论(0) 收藏
- Jakarta Struts学习之新手上路
- 微软编程之美2013全国挑战赛 资格赛 第1题
- 新手上路之图像处理学习心得
- 路由器设置新手上路---路由器设置结束
- 传话游戏(2013编程之美全国挑战赛资格赛)
- ubuntu12.04 .bashrc设置后无效 分类: ubuntu学习 2013-05-08 12:57 1402人阅读 评论(0) 收藏
- 新手上路,Kotlin学习笔记(二)---方法(函数)部分
- 2013编程之美资格赛【长方形】
- ACE学习笔记--新手上路(原创)