1.第一题 没有看

2. 由于数据范围很小,所以每一层需要全排列,寻找最小的花费,然后所有层加起来就是最后的结果。

  1. #include<bits/stdc++.h>
  2. #define pb push_back
  3. typedef long long ll;
  4. using namespace std;
  5. typedef pair<int, int> pii;
  6. const int maxn = 1e3 + ;
  7. int n;
  8. int m;
  9. int a[][][];
  10. int p[];
  11.  
  12. void solve() {
  13. cin >> n >> m;
  14. ll res = ;
  15. for (int j = ; j < n; j++) {
  16. cin >> a[][j][] >> a[][j][];
  17. }
  18. for (int i = ; i <= m; i++) {
  19. for (int j = ; j < n; j++) {
  20. cin >> a[i][j][] >> a[i][j][];
  21. }
  22. if(i == ) continue;
  23. for (int j = ; j < n; j++)
  24. p[j] = j;
  25. ll mr = INT_MAX;
  26. do {
  27. ll t = ;
  28. for (int j = ; j < n; j++) {
  29. t += abs(a[i][p[j] ][] - a[i - ][j][] ) + abs(a[i][p[j] ][] - a[i - ][j][] );
  30. }
  31. mr = min(t, mr);
  32. } while(next_permutation(p, p + n));
  33. res += mr;
  34. }
  35. cout << res << endl;
  36.  
  37. }
  38.  
  39. int main() {
  40. freopen("test.in", "r", stdin);
  41. //freopen("test.out", "w", stdout);
  42. ios::sync_with_stdio();
  43. cin.tie(); cout.tie();
  44. solve();
  45. return ;
  46. }

3.数据范围也是很小,枚举每一条边,然后存在不存在,进行判断累加。边的个数6 * 5  / 2 = 15. 1 << 15 = 32000. 然后乘上判断连通的复杂度,结果也是很小。

判断连通可以用bfs或者dfs, dsu都是可以的。

  1. #include<bits/stdc++.h>
  2. #define pb push_back
  3. typedef long long ll;
  4. using namespace std;
  5. typedef pair<int, int> pii;
  6. const int maxn = 1e3 + ;
  7. int n, m;
  8. //set<pii> se;
  9. int f[];
  10. int a[][];
  11. int b[][];
  12. void init() {
  13. for (int i = ; i <= n; i++) f[i] = i;
  14. }
  15. int fd(int x) {
  16. if(x == f[x]) return x;
  17. return f[x] = fd(f[x]);
  18. }
  19. bool check() {
  20. int sz = n;
  21. for (int i = ; i <= n; i++) {
  22. for (int j = i + ; j <= n; j++) {
  23. if(a[i][j]) {
  24. int t1 = fd(i);
  25. int t2 = fd(j);
  26. if(t1 != t2) {
  27. sz--;
  28. f[t1] = t2;
  29. }
  30. }
  31. }
  32. }
  33. return sz == ;
  34. }
  35. ll res;
  36.  
  37. void work(int x, int y) {
  38. //cout << x << " " << y << endl;
  39. if(x > n) {
  40. init();
  41. res += check();
  42. return;
  43. }
  44. if(y > n) {
  45. work(x + , x + );
  46. return;
  47. }
  48. work(x, y + );
  49. if(b[x][y]) return;
  50. a[x][y] = a[y][x] = ;
  51. work(x, y + );
  52. a[x][y] = a[y][x] = ;
  53. }
  54. void solve() {
  55. cin >> n >> m;
  56. int x, y;
  57. for (int i = ; i < m; i++) {
  58. cin >> x >> y;
  59. //if(x > y) swap(x, y);
  60. //se.insert({x, y});
  61. b[x][y] = b[y][x] = ;
  62. }
  63. work(, );
  64. cout << res << endl;
  65. }
  66.  
  67. int main() {
  68. freopen("test.in", "r", stdin);
  69. //freopen("test.out", "w", stdout);
  70. ios::sync_with_stdio();
  71. cin.tie(); cout.tie();
  72. solve();
  73. return ;
  74. }

4. 第四题稍微花了一些时间。 首先题目求解满足条件的最小, 那就是比这个大的都是可以满足条件的, 满足二分的性质。

然后给定答案,如何快速的判断是否满足要求, 贪心策略进行。由于 n = 1e4, 这个数其实挺小的, 排序, 贪心 可以的。

  1. #include<bits/stdc++.h>
  2. #define pb push_back
  3. typedef long long ll;
  4. using namespace std;
  5. typedef pair<int, int> pii;
  6. const int maxn = 1e4 + ;
  7. int n, a, b;
  8. ll h[maxn];
  9. ll tmp[maxn];
  10. int tot;
  11. bool check(ll x) {
  12. ll ra, rb;
  13. ra = rb = ;
  14. tot = ;
  15. for (int i = ; i < n; i++) {
  16. if(h[i] >= x) {
  17. ll c = h[i] / x;
  18. if(ra + c > a) {
  19. ll t = h[i] - x * (a - ra);
  20. ra = a;
  21. if(t > ) tmp[tot++] = t;
  22. } else {
  23. ra += h[i] / x;
  24. int t = h[i] % x;
  25. if(t > ) tmp[tot++] = t;
  26. }
  27.  
  28. } else {
  29. tmp[tot++] = h[i];
  30. }
  31. //if(ra > a) return 0;
  32. }
  33. sort(tmp, tmp + tot, greater<ll>());
  34. for (int i = ; i < tot; i++) {
  35. if(ra < a) {
  36. ra++;
  37. } else {
  38. rb += tmp[i];
  39. }
  40. }
  41. return ra + rb <= b;
  42. }
  43. void solve() {
  44. cin >> n >> a >> b;
  45. for (int i = ; i < n; i++) {
  46. cin >> h[i];
  47. }
  48. sort(h, h + n, greater<ll>());
  49. ll left = , right = 1e9 + ;
  50. while(left < right) {
  51. ll mid = (left + right) / ;
  52. //cout << mid << " " << left << " " << right << endl;
  53. if(check(mid)) right = mid;
  54. else left = mid + ;
  55.  
  56. }
  57. if(check(left)) cout << left << endl;
  58. else cout << - << endl;
  59. }
  60.  
  61. int main() {
  62. //freopen("test.in", "r", stdin);
  63. //freopen("test.out", "w", stdout);
  64. ios::sync_with_stdio();
  65. cin.tie(); cout.tie();
  66. solve();
  67. return ;
  68. }

indeed 4.22 第一次网测的更多相关文章

  1. indeed2017校招在线编程题(网测)三

    A. Calculate Sequence 分析:就是斐波那契递推公式,但是初始值是指定的,只用求第10个数,数据范围和复杂度都比较小,直接写. B. 忘了叫啥了. 就是有a-j十个字符组成的字符串, ...

  2. 2014-CVTE网测部分软件技术测试题及答案

    1.叉树的先序遍历序列和后序遍历序列正好相反,则该二叉树满足的条件是(D) A.空或只有一个结点 B.高度等于其结点数 C.该二叉树是完全二叉树 D.所有结点无右孩子 应该是二叉树的每个结点都只有一个 ...

  3. wap网测一道题目

    1. 给定一个字符串s, 1 <= len(s) <= 3000, 定义odd palindrome string为长度为奇数的回文串, 求s中该奇回文串的个数. 比如axbcba , 结 ...

  4. wap 5.23 网测几道题目

    1. n个犯人,m个省份, 如果相邻的2个犯人来自同一省份,则是不安全的,求不安全的个数. 正难则反,用全部的个数减去非法的个数,就是最后的答案. m^n - m * (m - 1) ^ (n - 1 ...

  5. 5.27 indeed 第三次网测

    1. 第一题, 没有看 2. 暴力枚举.每一个部分全排列, 然后求出最大的请求数. #include<bits/stdc++.h> #define pb push_back typedef ...

  6. indeed 5.13 第二次网测

    题目描述,我找不见了,大概写一下想法和代码吧. 1. 没有看 2. 由于数据范围很小,就是简单的枚举,求全排列,然后更新答案. #include<bits/stdc++.h> #defin ...

  7. elasticsearch系列(二) esrally压测

    环境准备 linux centOS(工作环境) python3.4及以上 pip3 JDK8 git1.9及以上 gradle2.13级以上 准备过程中的坑 这些环境准备没什么太大问题,都是wget下 ...

  8. mysql每秒最多能插入多少条数据 ? 死磕性能压测

    前段时间搞优化,最后瓶颈发现都在数据库单点上. 问DBA,给我的写入答案是在1W(机械硬盘)左右. 联想起前几天infoQ上一篇文章说他们最好的硬件写入速度在2W后也无法提高(SSD硬盘) 但这东西感 ...

  9. 使用Holer外网SSH访问内网(局域网)Linux系统

    1. Holer工具简介 Holer exposes local servers behind NATs and firewalls to the public internet over secur ...

随机推荐

  1. sql的四种连接方式

    1.内联接.(典型的联接运算,使用像 =  或 <> 之类的比较运算符).包括相等联接和自然联接. 内联接使用比较运算符根据每个表共有的列的值匹配两个表中的行.例如,检索 students ...

  2. os、sys模块

    os模块 os模块是与操作系统交互的一个接口 os.makedirs("dirname1/dirname2") # 可生成多层递归目录 os.removedirs("di ...

  3. 46.颜色+品牌下钻分析时按最深层metric进行排序

    主要知识点: 在做下钻分析时的排序     需求,以颜色进行bucket,这里bucket里面的doc以其各品牌的平均价格排序,     GET /tvs/sales/_search { " ...

  4. 垂直相邻margin合并解决方法

    块级元素的垂直相邻外边距会合并,水平边距永远不会重合. 行内元素实际上不占上下外边距,左右外边距也不会合并.浮动元素的外边距也不会合并. 外边距重叠的意义 外边距的重叠只产生在普通流文档的上下外边距之 ...

  5. HDU 3208 Integer’s Power

    Integer’s Power Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...

  6. LightOJ 1370 Bi-shoe and Phi-shoe

    /* LightOJ 1370 Bi-shoe and Phi-shoe http://lightoj.com/login_main.php?url=volume_showproblem.php?pr ...

  7. ZooKeeper环境搭建(单机/集群)(转)

    前提: 配置文件主要是在$ZOOKEEPER_HOME/conf/zoo.cfg,刚解压时为zoo_sample.cfg,重命名zoo.cfg即可. 配置文件常用项参考:http://www.cnbl ...

  8. 循环A表,根据查询结果,更新A表字段

    create or replace procedure prc_user_xtzx_match(p_flag out varchar2) IS xingming_match_loginname ); ...

  9. ios单元測试之GHUnit

    1.相同创建一个測试的project, 2.通过cocoaPod来下载GHUnit框架,或者到github上下载.由于这个框架是开源的第三方框架. 同一时候加入QuartCore.framework( ...

  10. 【BASH】bash shell的使用实例

    ************************************************************************ ****原文:blog.csdn.net/clark_ ...