#1835 : K-Dimensional Foil II

时间限制:1000ms
单点时限:1000ms
内存限制:256MB

描述

"K-Dimensional Foil" is a dimensional weapon. Its function is quite easy: It can ascend a region in 3D space to K (K≥3) dimension. One can use it to give the enemy unexpected attack. It was called "The Ultimate Weapon".

--"Remembrance of Mars's Past"

You are the chief technology officer in the space fleet, and your fleet was just suffered from the attack of the K-Dimensional Foil. The good news was that you have found the key parameter K, the dimension of the space. But staying in high dimensional space is very dangerous, you must destroy the K-Dimensional Foil as fast as possible.

You have n spaceships, spaceship i locates at si = (si,1, …, si,K), and the K-Dimensional  Foil is a 1-norm ball with center c = (c1, …, cK) and radius r, a 1-norm ball with center c and radius r is a point set defined as
{x |  d(x, c)  ≤ r}, d(x, c) =∑| xi - ci |

In the formula above, the coordinate of point x is (x1, x2 … xK)

Your spaceships will fire laser cannon to destroy the K-Dimensional Foil. The energy decay is very quick with the increase of the distance in the high dimensional space, so for every spaceship, you want to find the closest point (in Euclidean distance) on the K-Dimensional Foil. It's guaranteed that no spaceship is in the K-Dimensional Foil initially.

输入

The first line of the input is an integer T (T ≤ 100), the number of the test cases.

For each test case, the first line contains two integer n, K (1 ≤ n ≤ 50, 1 ≤ K ≤ 100), the number of spaceship in your fleet and the dimension of the space.

Then one line contains an integer r (1 ≤ r ≤ 104 ), the radius of the K-Dimensional Foil.

Then one line contains K integers c1, … cK, meaning the coordinate of the center of the K-Dimensional Foil.

Then n lines follow. Each line contains K integers si,1, …, si,K, meaning the coordinate of a spaceship.

All the absolute values of the coordinate are smaller than 104.

输出

For each test case, output n lines. The ith line contains K numbers representing the coordinate of the closest point on the K-Dimensional Foil to the ith spaceship. The absolute error between your output and the answer should be less than 10-4

提示

The K-Dimensional Foil in the sample was a square with vertex: (1,0), (0,1), (-1,0), (0,-1)

This problem is special judged.

样例输入
1
2 2
1
0 0
1 1
1 3
样例输出
0.50 0.50
0.00 1.00

题目大意:忽略曼哈顿面的中心,平移所有顶点后,简化为数学语言便是已知

Σ|ai|== R

求使

Σ(yi-ai)²

的值最小的ai数组。

从二维思考到高维度,假设坐标 yi 全部大于0,当这种情况出现时,最近的点一定在第一象限,也就是 ai >= 0。

则 设 L(a) = (Σ|ai| - R)

当yi全部满足 yi>=0时,假设ai>=0

则 L(a) = λ*(Σai - R)

则 F(a) = Σ(yi-ai)² + L(a)

对于每一个ai求偏导数,最后化简得到

λ = 2(Σyi - R)/n

ai = yi - λ

当得到ai < 0时与假设不符,调整ai为0,继续重复操作直到所有ai均不小于0

最后调整符号为对应“象限”。

#include <bits/stdc++.h>
#define P(n, f) cout<<n<<(f?'\n':' ')
#define pi pair<int,int>
#define LL long long
#define ULL unsigned long long
#define lowbit(x) x&(-x)
#define mp make_pair
#define elif else if
#define range(i, a, b) for(auto i=a;i<=b;++i)
#define itrange(i, a, b) for(auto i=a;i!=b;++i)
#define rerange(i, a, b) for(auto i=a;i>=b;--i)
#define fill(arr, tmp) memset(arr,tmp,sizeof(arr))
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
vector<string>ret;
vector<string>::iterator END;
bool cmp(const string &a,const string &b){return a.size()!=b.size() ?a.size() > b.size():a<b;
}
bool can[105];
double a[105];
void deal(vector<pair<int,int > >&y,int R) {memset(can, -1, sizeof(can));bool flag;int cur = y.size();int cnt = 0;do {flag = false;int res = 0;for (int i = 0; i < y.size(); ++i) {if (can[i])res += y[i].first;///绝对值
        }double lambda = 1.0 * (res - R) / cur;for(int i = 0 ; i < y.size() ; ++i){if(can[i]){a[i] = y[i].first - lambda;if(a[i] < 0){can[i] = false;a[i] = 0;flag = true;--cur;}}}}while (flag);for(int i = 0 ; i < y.size() ; ++i){a[i]*=y[i].second;///符号
    }
}vector<pair<int,int> >Data;
int ORI[105];
int n,x,y,k,tmp;
int FUN(int a){if(a)return abs(a)/a;else return 1;
}
void init() {int T,R;cin>>T;while (T--) {cin>>n>>k>>R;range(i, 1, k) {scanf("%d",ORI+i-1);}range(i, 1, n) {Data.clear();range(j, 1, k) {scanf("%d",&tmp);Data.emplace_back(make_pair(abs(tmp - ORI[j - 1]), FUN(tmp - ORI[j - 1])));}deal(Data, R);for(int ___ = 0 ; ___ < k ; ++___){printf("%.5lf",a[___]+ORI[___]);if(___!=k-1)printf(" ");else puts("");}}}
}void solve() {}int main() {init();solve();return 0;
}

嗯,目标函数时平方函数 yi ai同号才是最小值。

然后就变成一道水题了?

(纪念没加原点坐标吃下的罚时)

转载于:https://www.cnblogs.com/DevilInChina/p/9691126.html

ACM-ICPC 2018 北京网络赛:K-Dimensional Foil II相关推荐

  1. 2011 ACM/ICPC 福州赛区网络赛解题报告

    第一次写网络赛的题解,福州赛区网络赛作为我第一年ACM最后一次网络赛酱油,画了一个很像逗号的句号.....好吧,还得为北京现场赛准备啊准备....... 这次酱油打的很犀利,貌似出第一题很快,之后节奏 ...

  2. ACM-ICPC 2018 北京网络赛:K-Dimensional Foil II 一题多解

    博客目录 原题 题目链接 #1835 : K-Dimensional Foil II 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 "K-Dimensional ...

  3. 2014 ACM/ICPC 鞍山赛区网络赛(清华命题)

    为迎接10月17号清华命题的鞍山现场赛 杭电上的题目 Biconnected(hdu4997)     状态压缩DP Rotate(hdu4998)    相对任一点的旋转 Overt(hdu4999 ...

  4. Saving Tang Monk II HihoCoder - 1828(2018北京网络赛三维标记+bfs)

    <Journey to the West>(also <Monkey>) is one of the Four Great Classical Novels of Chines ...

  5. 2018北京网络赛 HihoCoder - 1835 K-Dimensional Foil II 计算几何 贪心 二分

    题目链接:https://vjudge.net/problem/HihoCoder-1835 题解:首先我们应该能想到到达图形的距离最近那肯定是垂直过去,也就是坐标变为(x1 - k, x2 - k, ...

  6. 2016 ICPC 北京网络赛 A 恶心模拟 F 循环矩阵,FFT(待补) I 模拟

    2016 ICPC 北京网络赛 A - The Book List 题意:每本书有所属种类,给出原生的存放方式,求按新的方式存放的样子. tags:坑到心态爆炸的题==  直接堆进vector里搞的, ...

  7. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  8. 2018宁夏网络赛 B Goldbach (米勒拉宾素数测试)

    2018宁夏网络赛 B Goldbach (米勒拉宾素数测试) 题目链接 题目大意: 给你一个偶数n (2<n<=1e18) 让你把n分解成两个素数的和.(如果有多个输出任意一个) 解题思 ...

  9. ACM/ICPC 2018亚洲区预选赛北京赛站网络赛 【bfs + 记忆化搜索 + 剪枝】 AC 代码

    ACM 北京区域赛 bfs+剪枝+ms 第一个一遍过的题目,基本没有看题解 记忆搜索当中,注意初始化成一个特殊值:而在访问之后,每个点就会有一个不同于INF(或者 -1等特殊标记)的值 先到先得,适者 ...

最新文章

  1. 【Android 热修复】热修复原理 ( 热修复框架简介 | 将 Java 字节码文件打包到 Dex 文件 )
  2. 使用HTML文件作为中转生成WORD文档
  3. GCD LCM UVA - 11388 (思维。。水题)
  4. 注册中心—组件—ZooKeeper
  5. 中煤保险 公司举办“虎啸杯”保险知识竞赛活动
  6. iOS - UIView属性hidden, opaque, alpha, opacity的区别
  7. 我被产品小姐姐的笔记本深深吸引了....
  8. 《Java多线程编程核心技术》读书笔记
  9. static_cast、dynamic_cast、const_cast和reinterpret_cast总结(转)
  10. [渝粤教育] 西南科技大学 政治经济学 在线考试复习资料
  11. jQuery 中的 attr
  12. Xenserver console界面无法查看虚拟机的信息
  13. LintCode_408 二进制求和
  14. 围棋AI kataGo下载
  15. 双频wifi是什么意思 双频wifi好处有哪些
  16. AutoCAD 2021-2022
  17. HTML的表单及框架
  18. 服务器显示器无法调节分辨率,求救:分辨率调的太高,显示器无法显示怎么办?...
  19. 蓝桥杯——鲁卡斯队列
  20. 什么是Android手机

热门文章

  1. 旋转卡壳——凸多边形直径
  2. NLP / LLMs中的Temperature 是什么?
  3. OpenCV 画点 画线 画框 写字操作
  4. JBL CM102 有源监听音箱使用体验
  5. 全方位揭秘!大数据从0到1的完美落地之Hive视图
  6. Vue3 - 插槽 Slots
  7. 【散文】 一个人的旅行
  8. 阿里巴巴为什么能抗住双十一?看完这篇你就明白了!
  9. 老游戏新写之Jetpac重返地球
  10. 曾经的豪言壮语,如今的喟然长叹