社区讨论
关于对ios的疑问
学术版参与者 9已保存回复 11
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 11 条
- 当前快照
- 1 份
- 快照标识符
- @mdii7yxf
- 此快照首次捕获于
- 2025/07/25 15:32 7 个月前
- 此快照最后确认于
- 2025/11/04 06:29 4 个月前
rt,同样的代码,在加上
CPPios::sync_with_stdio(0);cin.tie(0);cout.tie(0);后交同一道题会得到不同的分数,请问这是为什么?#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define N 86
using namespace std;
struct node{
double x,y;
}a[N];
int n;
double ans=2e30;
bool used[N];
inline int read();
inline void dfs(double x,double y,double sum,int cnt);
inline bool cmp(node x,node y);
inline double get_x(double x,double y,double xx,double yy);
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
n=read();
for(int i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
}
sort(a+1,a+1+n,cmp);
// dfs(0,0,0,0,0);
dfs(0,0,0,0);
printf("%.2lf\n",ans);
return 0;
}
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-48;ch=getchar();}
return x*f;
}
inline void dfs(double x,double y,double sum,int cnt){
if(sum>=ans) return;
if(cnt==n){
ans=sum;
return;
}
for(int i=1;i<=n;i++){
if(!used[i]){
used[i]=1;
dfs(a[i].x,a[i].y,get_x(x,y,a[i].x,a[i].y)+sum,cnt+1);
used[i]=0;
}
}
}
inline bool cmp(node x,node y){
if(x.x!=y.x) return x.x<y.x;
return x.y<y.y;
}
inline double get_x(double x,double y,double xx,double yy){
return sqrt(1.0*(x-xx)*(x-xx)+1.0*(y-yy)*(y-yy));
}
CPP#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define N 86
using namespace std;
struct node{
double x,y;
}a[N];
int n;
double ans=2e30;
bool used[N];
inline int read();
inline void dfs(double x,double y,double sum,int cnt);
inline bool cmp(node x,node y);
inline double get_x(double x,double y,double xx,double yy);
int main(){
n=read();
for(int i=1;i<=n;i++){
cin>>a[i].x>>a[i].y;
}
sort(a+1,a+1+n,cmp);
// dfs(0,0,0,0,0);
dfs(0,0,0,0);
printf("%.2lf\n",ans);
return 0;
}
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-48;ch=getchar();}
return x*f;
}
inline void dfs(double x,double y,double sum,int cnt){
if(sum>=ans) return;
if(cnt==n){
ans=sum;
return;
}
for(int i=1;i<=n;i++){
if(!used[i]){
used[i]=1;
dfs(a[i].x,a[i].y,get_x(x,y,a[i].x,a[i].y)+sum,cnt+1);
used[i]=0;
}
}
}
inline bool cmp(node x,node y){
if(x.x!=y.x) return x.x<y.x;
return x.y<y.y;
}
inline double get_x(double x,double y,double xx,double yy){
return sqrt(1.0*(x-xx)*(x-xx)+1.0*(y-yy)*(y-yy));
}
回复
共 11 条回复,欢迎继续交流。
正在加载回复...