HDU 4995Revenge of kNN(暴力)
来源:互联网 发布:电脑能写小说的软件 编辑:程序博客网 时间:2024/06/05 10:50
http://acm.hdu.edu.cn/showproblem.php?pid=4995
暴力,代码还没调对,这种题意不明的模拟题真的烦死了
#include<iostream>#include<cstdio>#include<set>#include<string>#include<string.h>#include<cstring>#include<vector>#include<map>#include<queue>#include<stack>#include<cctype>#include<algorithm>#include<sstream>#include<utility>#include<cmath>#define mt(a) memset(a,0,sizeof (a))#define fl(a,b,c) fill(a,b,c)#define SWAP(a,b,t) (t=a,a=b,b=t)#define inf 1000000using namespace std;typedef long long ll;typedef struct Node{ll pos,id;}Node;double val[100000 + 20];bool com(Node x, Node y){return x.pos < y.pos;}vector<Node>v;map<ll, ll>ma;int main(){int T;cin >> T;while (T--){v.clear();ma.clear();int n, m, k;scanf("%d %d %d", &n, &m, &k);for (int i = 0; i < n; i++){ll x;double y;scanf("%lld %lf", &x, &y);Node T;T.pos = x; val[i] = y; T.id = i + 1;v.push_back(T);}sort(v.begin(), v.end(), com);for (int i = 0; i < n; i++){ma[v[i].id] = i;}double ans = 0.0;for (int i = 0; i < m; i++){ll q;ll pr, pl, pos;scanf("%lld", &q);pos = ma[q];pl = pos, pr = pos;double sum = 0.0;ll time = k;for (int j = 0; j < k;j++){if ((pl - 1 >= 0) && (pr + 1 < n)){if (abs(v[pl - 1].pos - v[pos].pos) <= (abs(v[pr + 1].pos - v[pos].pos)))sum += val[--pl];elsesum += val[++pr];}else if (pl - 1 >= 0)sum += val[--pl];elsesum += val[++pr];}val[pos] = sum / k;ans += val[pos];}printf("%.6lf\n", ans);}return 0;}
第二版 WA 待修改
#include<iostream>#include<cstdio>#include<set>#include<string>#include<string.h>#include<cstring>#include<vector>#include<map>#include<queue>#include<stack>#include<cctype>#include<algorithm>#include<sstream>#include<utility>#include<cmath>#define mt(a) memset(a,0,sizeof (a))#define fl(a,b,c) fill(a,b,c)#define SWAP(a,b,t) (t=a,a=b,b=t)#define inf 1000000using namespace std;typedef long long ll;typedef struct Node{ll pos, id;double val;}Node;bool com(Node x, Node y){return x.pos < y.pos;}vector<Node>v;map<ll, ll>ma;int main(){int T;cin >> T;while (T--){v.clear();ma.clear();int n, m, k;scanf("%d %d %d", &n, &m, &k);for (int i = 0; i < n; i++){ll x, y;scanf("%lld %lld", &x, &y);Node T;T.pos = x; T.val = y; T.id = i + 1;v.push_back(T);}sort(v.begin(), v.end(), com);vector<Node>::iterator po1, po2;for (int i = 0; i < n; i++){ma[v[i].id] = i;}double ans = 0.0;for (int i = 0; i < m; i++){ll q;ll pr, pl, pos;scanf("%lld", &q);pos = ma[q];pl = pos, pr = pos;double sum = 0.0;ll time = k;for (int j = 0; j < k; j++){if ((pl - 1 >= 0) && (pr + 1 < n)){if (abs(v[pl - 1].pos - v[pos].pos) > (abs(v[pr + 1].pos - v[pos].pos))){sum += v[++pr].val;}else{sum += v[--pl].val;}}else if (pl - 1 >= 0){sum += v[--pl].val;}else{sum += v[++pr].val;}}v[pos].val = sum / k;ans += v[pos].val;}printf("%.6lf\n", ans);}return 0;}
0 0
- 【HDU】4995 Revenge of kNN 暴力
- HDU 4995Revenge of kNN(暴力)
- hdu 4995 Revenge of kNN(暴力枚举)
- hdu 4995 Revenge of kNN
- HDU 4995 Revenge of kNN
- hdu 4995 Revenge of kNN
- HDU 4995 Revenge of kNN
- hdu 4995 Revenge of kNN (模拟)
- hdu 4995 Revenge of kNN(模拟)
- 【HDU 5021】 Revenge of kNN II
- HDU 5019 Revenge of GCD (暴力)
- HDU 4993Revenge of ex-Euclid(暴力)
- 【杂题】 HDOJ 4995 Revenge of kNN
- HDU 5021 Revenge of kNN II 线段树
- 【HDU】5021 Revenge of kNN II 树状数组
- BC D Revenge of kNN II hdu 5021
- hdu 5021 Revenge of kNN II(树状数组)
- HDU 4993 Revenge of ex-Euclid(数学题 暴力)
- 多线程开发
- Servlet知识点<一>
- 使用 robolectric 做单元测试
- iOS开发Runtime那些事
- Linux下的sock_stream和sock_dgram
- HDU 4995Revenge of kNN(暴力)
- 罗马数字转换为十进制数字
- Node:Q与node http模块搭配
- Servlet知识点<二>
- 判断一个数是否是2^N次方
- MATLAB 解不等式组
- 读《点石成金》
- 线程池
- 计算机程序工作原理———简单c程序实例剖析