【USACO4.2.4】奶牛自行车
来源:互联网 发布:小鸭淘宝复制软件 编辑:程序博客网 时间:2024/05/02 01:41
其实是个水题,就按照题目意思来。
但是我题目意思看错了3次…… 写了3个多小时……
Executing... Test 1: TEST OK [0.008 secs, 3396 KB] Test 2: TEST OK [0.095 secs, 3396 KB] Test 3: TEST OK [0.054 secs, 3396 KB] Test 4: TEST OK [0.127 secs, 3396 KB] Test 5: TEST OK [0.267 secs, 3396 KB] Test 6: TEST OK [0.165 secs, 3396 KB] Test 7: TEST OK [0.292 secs, 3396 KB] Test 8: TEST OK [0.475 secs, 3396 KB]All tests OK.
for (back_min = r1; back_min + R - 1 <= r2; ++ back_min)// 穷举后轮最小值back_min{for (back_max = back_min + R - 1; back_max <= r2; ++ back_max) //后轮最大值back_max{for (front_min = f1; front_min + F - 1 <= f2; ++ front_min) //前轮最小值,{for (front_max = front_min + F - 1; front_max <= f2; ++ front_max) //前轮最大值{if (front_min * back_min * 3 > front_max * back_max)continue; //直接不符合要求,退出usd1[1] = front_min;usd2[1] = back_min;usd2[R] = back_max;usd1[F] = front_max;if (F == 1) dfs_front(front_min, 0);else dfs_front(front_min, 1);}}}}
强行穷举前后轮最大值最小值范围,然后根据题目的条件的,大小轮子比率3倍,来直接剪掉一些范围,然后在范围内进行枚举,求解
我是用2个DFS强行穷举出所有情况,然后计算方差。
先看成是选择轮子的方差了……然后又看成是轮子比率的方差,
结果求的是—— 轮子比率排序后的差的方差……
/*TASK:cowcycleLANG:C++*/#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;//F,R为1的情况暂时没有考虑int F, R;int f1, f2, r1, r2;void init(){cin >> F >> R;cin >> f1 >> f2;cin >> r1 >> r2;}int back_min, back_max, front_min, front_max;//int ansint usd1[100], usd2[100], tot1;int output_usd1[100], output_usd2[100];double ans=10000000000;double p[1000],pp[1000];int tp, tt;inline void check(){tp = tt = 0;for (int i = 1; i <= F; ++ i)for (int j = 1; j <= R; ++ j)pp[++tp] = (double)usd1[i] / (double)usd2[j];sort(pp + 1, pp + 1 + tp);for (int i = 1; i < tp; ++ i)p[i] = pp[i + 1] - pp[i];--tp;double ave,tot(0), tmp(0);for (int i = 1; i <= tp; ++ i)tot += p[i];ave = tot / tp;for (int i = 1; i <= tp; ++ i)tmp += (p[i] - ave) * (p[i] - ave);tmp /= tp;if (tmp == ans){for (int i = 1; i <= F; ++ i){if (usd1[i] < output_usd1[i])goto ok1;if (usd1[i] > output_usd1[i])return;}for (int i = 1; i <= R; ++ i){if (usd2[i] < output_usd2[i])goto ok1;if (usd2[i] > output_usd2[i])return;}}if (tmp < ans){ans = tmp;ok1:;memmove(output_usd1 + 1, usd1 + 1, sizeof(int) * F);memmove(output_usd2 + 1, usd2 + 1, sizeof(int) * R);}}void dfs_back(int k,int tot){if (back_max - k + 1 < R - tot)return;if (tot == R - 1){check();return;}usd2[tot + 1] = k;dfs_back(k + 1, tot + 1);dfs_back(k + 1, tot);}void dfs_front(int k, int tot){if (front_max - k + 1 < F - tot)return; //不够填充的,returnif (tot == F - 1) //最后一格直接填进去{dfs_back(back_min + 1, 1);return ;}usd1[tot + 1] = k;//第tot个数字选择kdfs_front(k + 1, tot + 1);dfs_front(k + 1, tot);}void doit(){for (back_min = r1; back_min + R - 1 <= r2; ++ back_min)// 穷举后轮最小值back_min{for (back_max = back_min + R - 1; back_max <= r2; ++ back_max) //后轮最大值back_max{for (front_min = f1; front_min + F - 1 <= f2; ++ front_min) //前轮最小值,{for (front_max = front_min + F - 1; front_max <= f2; ++ front_max) //前轮最大值{if (front_min * back_min * 3 > front_max * back_max)continue; //直接不符合要求,退出usd1[1] = front_min;usd2[1] = back_min;usd2[R] = back_max;usd1[F] = front_max;if (F == 1) dfs_front(front_min, 0);else dfs_front(front_min, 1);}}}}for (int i = 1; i < F; ++ i)cout<<output_usd1[i]<<" ";cout<<output_usd1[F]<<endl;for (int i = 1; i < R; ++ i)cout<<output_usd2[i]<<" ";cout<<output_usd2[R]<<endl;}int main(){freopen("cowcycle.in", "r",stdin);freopen("cowcycle.out","w",stdout);init();doit();return 0;}
0 0
- 【USACO4.2.4】奶牛自行车
- 自行车
- 自行车
- 自行车
- 自行车
- 自行车自行车自行车自行车
- 自行车
- 奶牛
- usaco4.3.2
- usaco4.4.2
- 自行车自行车在
- 自行车自行车现在才
- USACO4.1.4 Cryptcowgraphy
- USACO4.2.3/job
- USACO4.2.1/ditch
- 【USACO4.1.1】麦香牛块
- usaco4.1.1Beef McNuggets
- # USACO4.4 三道题
- PHP数据结构大全地址之->模拟静态队列
- 【USACO4.2.1】草地排水 最大流
- 【USACO4.2.2】完美的牛栏 二分图的匹配
- 实用,修改Ecshop后台商品管理中的商品品牌项为可分组和搜索的下拉框
- 大型网站服务器架构
- 【USACO4.2.4】奶牛自行车
- 你想建设一个能承受500万PV/每天的网站吗?如何计算呢?
- 递归实现汉诺塔问题
- 黑马程序员---异常
- [python学习] 模仿浏览器下载CSDN源文并实现PDF格式备份
- 百万连接之路
- 黑马程序员---多线程(一)
- 一个out of socket memory的问题
- HTTP长连接200万尝试及调优方法