博客目录

原题

题目链接

#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

思路一:越界降维

(注意一范数的意思是取绝对值再求和,所以多维平面不是我们平时的平方的球,而是一次的菱形(比如二维的是|x|+|y|=r))

直线的参数方程(一个点和方向向量:)

求一个点到平面的投影:

我们为了简化计算,可以将坐标平移置圆心在0点。根据对称性再将飞船坐标取绝对值转化到第一象限。最后再转化回来即可

然后对于有些坐标求出来是负数,说明这个维度的极值为0,(第一象限最小值为0而不是负数),然后我们就确定了这个维度为0,降一维之后从头重新解方程,直到所有坐标算出来不为负数即可,然后转化回来坐标输出。

思路二、贪心二分代替方程,不用降维

实际上我们贪心的去想:对于下式

                                                                          

如果我们有这么一种操作可以把某个减一,现在问一次操作后S的最小值,

那么很容易便可以知道我们肯定是去找最大的那个去减一,最后的结果才会最小.

对于这道题其实也一样,我们肯定也是选相对于圆心数值的差(加绝对值)大的维度优先去减小,这样一直贪心下去,

最后落到上面的点肯定就是我们要求的点。

对于这样一种操作,我们可以发现,在经过若干次操作后,这k个维度的向量的长度的最大的那几个肯定数值是相等的,

这是由于我们贪心的选取最大的去减所导致的,由于我们每次减的数值很小,误差小于题目中给的1e-4,那么对于结果来说数值就是无误的.

这样一来,对于这么些操作我们便可以用二分去替代,二分我们最后划定的那个最大值的数值便可以解决此问题。

AC代码一

#include<bits/stdc++.h>
#include<cstring>
using namespace std;
typedef long long ll;
typedef long double lb;
int const maxn=105;
lb ori[maxn],p[maxn];
int s[maxn];
lb ans[maxn];
bool f[maxn];
lb aim[maxn];
int main(){
    #ifndef ONLINE_JUDGE
    freopen("r.txt","r",stdin);
    #endif 
    int T,n,k,r,t;
    cin>>T;
    lb sum;
    while(T--){
        scanf("%d%d",&n,&k);
        scanf("%d",&r);s
        for(int i=0;i<k;i++){
            scanf("%d",&t);
            ori[i]=t; 
        } 
        while(n--){
            for(int j=0;j<k;j++){
                scanf("%d",&t);
                p[j]=t-ori[j];
                s[j]=p[j]>0?1:-1;
                p[j]=abs(p[j]);
            }
            sum=-r;
            for(int j=0;j<k;j++){
                sum+=p[j];
            }
            int dim=0;
            lb len,ab;
            bool flag=0;
            memset(f,0,sizeof(f));
            while(dim<k){
                len=sum/(k-dim);
                flag=0;
                for(int j=0;j<k;j++){
                    if(!f[j]){
                        aim[j]=p[j]-len;
                        if(aim[j]<0){
                            aim[j]=0;
                            f[j]=1;
                            sum-=p[j];
                            dim++;
                            flag=1;
                            break;
                        }
                    }
                }
                if(flag==0){
                    break;
                }
            }
            for(int j=0;j<k;j++){
                printf("%.4Lf ",aim[j]*s[j]+ori[j]);
            }
            printf("\n");
        }
    } 
}

AC代码二

#include<bits/stdc++.h>
using namespace std;
double eps=1e-6;
double c[105],s[105];
double conv[105];
double ans[105];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,k,r;
        scanf("%d%d",&n,&k);
        scanf("%d",&r);
        for(int i=1;i<=k;i++) scanf("%lf",&c[i]);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=k;j++) scanf("%lf",&s[j]),conv[j]=abs(s[j]-c[j]);
            double L=0,R=1e8;
            while(L<R-eps)  
            {
                double mid=(L+R)/2.0;
                double sum=0;
                for(int j=1;j<=k;j++) sum+=max(0.0,conv[j]-mid);
                if(sum<=r) R=mid;
                else L=mid;
            }
            for(int j=1;j<=k;j++)
            {
                if(conv[j]>=R) conv[j]=R;
                if(s[j]>c[j]) ans[j]=-conv[j]+s[j];
                else ans[j]=conv[j]+s[j];
                printf("%.5f ",ans[j]);
            }
            printf("\n");
        }
    }
}

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 Foil" i ...

  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. 2018焦作网络赛 - Poor God Water 一道水题的教训

    本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...

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

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

  8. ICPC 2019 徐州网络赛

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

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

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

最新文章

  1. etcd 笔记(03)— etcd 客户端使用(键值的增、删、改、查)、watch监测键、lease使用(创建租约、撤销租约、刷新租期、查询租期)
  2. Thrift架构与使用方法
  3. docker logstash_用于监视Kubernetes和Docker的六大开源工具
  4. 【流媒体开发】VLC Media Player - Android 平台源码编译 与 二次开发详解 (提供详细800M下载好的编译源码及eclipse可调试播放器源码下载)
  5. encodeURIComponent编码2次
  6. 查看Mysql数据库有多大
  7. 安全密码存储–请勿做的事和Java示例
  8. try catch线程问题???
  9. 啊哈java_1.桶排序——啊哈算法java实现
  10. Epic Games表示不服苹果垄断案裁决 继续提出上诉
  11. Android学习——SharedPreferences
  12. mybatis 主键自增 insert后返回主键
  13. python怎么操作_python怎么操作mysql
  14. Openpyxl:读取/写入Excel文件的Python模块
  15. .net from 关闭事件_libVLC 事件机制
  16. 计算机体系结构基础 计算机系统评价和性能分析心得
  17. 前端(HTML css JS)开发工具及常用插件推荐
  18. [网络安全学习篇60]:文件上传
  19. 【Java写的碰碰球游戏(2) 】
  20. Project计算项目进度

热门文章

  1. 从 0 到 1 的 VR 界面设计之路
  2. 未来的计算机 展望未来作文,以展望未来为题的作文(精选4篇)
  3. Datepicker日期控件“今天”按钮点击没反应
  4. 都说人活一世,一定要走一趟大西北!
  5. 用SolidWorks打印3D小车底板
  6. MacBook长期待机导致网页视频无法播放
  7. diea 创建 maven 工程
  8. matlab选修结课作业,matlab结课作业
  9. Redis面试题系列:跳跃表
  10. 【项目】bxg基于SaaS的餐掌柜项目实战(2023)