【POJ1751】【坑,double 不能用memset】【sqrt i j写错了】

这篇博客记录了在解决POJ1751问题时遇到的陷阱,包括不能使用memset操作double类型变量以及在计算平方根过程中i和j的错误写法。博主分享了解决这些问题的经验和教训。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Highways
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 11244 Accepted: 3206 Special Judge

Description

The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian government is aware of this problem and has already constructed a number of highways connecting some of the most important towns. However, there are still some towns that you can't reach via a highway. It is necessary to build more highways so that it will be possible to drive between any pair of towns without leaving the highway system. 

Flatopian towns are numbered from 1 to N and town i has a position given by the Cartesian coordinates (xi, yi). Each highway connects exaclty two towns. All highways (both the original ones and the ones that are to be built) follow straight lines, and thus their length is equal to Cartesian distance between towns. All highways can be used in both directions. Highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways. 

The Flatopian government wants to minimize the cost of building new highways. However, they want to guarantee that every town is highway-reachable from every other town. Since Flatopia is so flat, the cost of a highway is always proportional to its length. Thus, the least expensive highway system will be the one that minimizes the total highways length. 

Input

The input consists of two parts. The first part describes all towns in the country, and the second part describes all of the highways that have already been built. 

The first line of the input file contains a single integer N (1 <= N <= 750), representing the number of towns. The next N lines each contain two integers, xi and yi separated by a space. These values give the coordinates of i th town (for i from 1 to N). Coordinates will have an absolute value no greater than 10000. Every town has a unique location. 

The next line contains a single integer M (0 <= M <= 1000), representing the number of existing highways. The next M lines each contain a pair of integers separated by a space. These two integers give a pair of town numbers which are already connected by a highway. Each pair of towns is connected by at most one highway. 

Output

Write to the output a single line for each new highway that should be built in order to connect all towns with minimal possible total length of new highways. Each highway should be presented by printing town numbers that this highway connects, separated by a space. 

If no new highways need to be built (all towns are already connected), then the output file should be created but it should be empty. 

Sample Input

9
1 5
0 0 
3 2
4 5
5 1
0 4
5 2
1 2
5 3
3
1 3
9 7
1 2

Sample Output

1 6
3 7
4 9
5 7
8 3

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top



#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
    
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp push_back

int n,m;
struct Node
{
	int x,y;
}node[1100];
double g[1100][1100];
int pre[1100];
double d[1100];
bool in[1100];
double dis(Node a,Node b)
{
	return sqrt(((double)(a.x-b.x)*(a.x-b.x)) + (a.y-b.y)*(a.y-b.y));
}

void prim(int st)
{
	d[st] = 0;
	for(int i=0;i<=n;i++)
	{
		double mins = 0x3f3f3f3f;
		int p = -1;
		for(int j=1;j<=n;j++)
		{
			if(!in[j] && d[j] < mins)
			{
				mins = d[j] ;
				p = j;
			}

		}

		if(p == -1)  break;
		in[p] = true;
		if(mins != 0 && pre[p] != -1)
		{
			printf("%d %d\n",pre[p],p);
		}

		for(int j=1;j<=n;j++)
		{
			if(!in[j] && d[j] > g[p][j])
			{
				d[j] = g[p][j];
				pre[j] =  p;
			}
		}
	}
}
int main()
{
    while(scanf("%d",&n) != EOF)
	{
		for(int i=0;i<=n;i++)
		{
			pre[i] = -1;
			d[i] = 0x3f3f3f3f;
			in[i] = false;
			for(int j=0;j<=n;j++)
			{
				g[i][j] = 0x3f3f3f3f;
			}
			g[i][i] = 0;
		}
		memset(node,0,sizeof(node));
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d",&node[i].x,&node[i].y);
		}
		
		for(int i=1;i<=n;i++)
		{
			for(int j=i+1;j<=n;j++)
			{
				g[i][j] = g[j][i] = sqrt((node[i].x-node[j].x)*(node[i].x-node[j].x) + (node[i].y-node[j].y)*(node[i].y-node[j].y));
			}
		}
		scanf("%d",&m);
		for(int i=0;i<m;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			g[u][v] = g[v][u] = 0;
		}

		prim(1);
	}
    return 0;
}


<think>好的,我现在需要帮用户解决如何获取System权限来操作文件夹的问题。首先,我得回忆一下用户提供的引用内容,看看有哪些方法可以参考。 用户提到了几个引用,其中引用[3]详细说明了通过文件属性修改权限的步骤。这可能是一个比较直观的方法,适合普通用户。用户需要右键点击文件夹,进入属性,然后找到安全选项卡,可能需要更改所有者并添加权限。这里要注意步骤中的细节,比如如何更改所有者到Administrators或当前用户,然后再添加完全控制权限。如果添加按钮不可用,可能需要先更改所有者,这一点很重要。 接下来,引用[2]提到使用PowerShell命令来强制删除文件。虽然用户的问题不是删除而是获取权限,但这里的命令可能适用。比如使用`cacls`或者`icacls`命令赋予管理员权限,然后进行操作。需要确认这些命令在获取System权限时是否有效,或者是否需要结合其他步骤。例如,先给文件夹赋权,再执行操作。 引用[4]提到了通过替换系统文件获取System权限,但这种方法可能风险较高,尤其是涉及系统文件时。用户需要谨慎,避免误删关键文件导致系统崩溃。这里可能需要更详细的步骤说明,或者建议用户优先使用更安全的方法。 引用[5]介绍了一个使用System权限的Explorer工具,适用于XP和Win7。不过用户现在可能使用的是更新的系统,如Win10或Win11,所以需要确认该方法是否仍然有效。此外,结束explorer.exe进程并以System权限重新启动可能会比较复杂,适合有一定经验的用户。 然后,我需要综合这些方法,整理出几种不同的解决方案,按照安全性和操作难度排序。属性修改法相对安全,适合大多数用户。命令行方法适合熟悉命令的用户,而替换系统文件或使用工具可能风险较高,作为备选方案。 同时,用户可能需要了解不同方法的适用场景和潜在风险。例如,修改系统文件可能导致系统不稳定,需特别提醒。此外,在操作前备份重要数据也是必要的注意事项。 最后,生成相关问题时要围绕获取权限的不同方法、命令行的具体使用、风险提示以及高级技巧等方面展开,帮助用户进一步理解和解决可能遇到的问题。</think>### 如何获取System权限操作文件夹 #### 方法一:通过文件属性修改权限(推荐新手) 1. **右键文件夹→属性→安全→高级** 点击"安全"选项卡→"高级"按钮进入高级安全设置[^3] 2. **更改文件夹所有者** 点击"所有者"后面的"更改"→输入`Administrators`→检查名称→确定 勾选"替换子容器和对象的所有者" 3. **添加完全控制权限** 返回"安全"选项卡→编辑→添加→输入`SYSTEM`→检查名称→勾选"完全控制"→确定[^3] #### 方法二:使用命令行强制赋权(推荐中级用户) ```powershell # 以管理员身份运行PowerShell cd C:\目标文件夹路径 takeown /F 文件夹名 /r /d y # 获取所有权[^2] icacls 文件夹名 /grant Administrators:F /t # 授予完全控制权[^2] icacls 文件夹名 /grant SYSTEM:F /t # 单独授予SYSTEM权限[^4] ``` #### 方法三:替换系统文件获取权限(高风险操作) ```cmd :: 需要管理员CMD执行 cacls C:\Windows\System32\sethc.exe /T /E /G administrators:F :: 将sethc.exe重命名为sethc.bak :: 复制cmd.exe并重命名为sethc.exe :: 连续按5次Shift键触发SYSTEM权限的CMD[^4] ``` #### 操作注意事项 1. **系统文件保护** C盘系统文件不可随意删除,可能导致系统崩溃[^1] 2. **权限继承机制** 使用`/t`参数可对子文件夹递归操作,使用`/e`保留原有权限[^2] 3. **特殊权限说明** TrustedInstaller权限高于SYSTEM,需额外处理[^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值