一开始
写模板
(在编译器里加了-DLOCAL)
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define print(e) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<endl
#define print2(e,f) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<","<<#f<<"=\""<<(f)<<"\""<<endl
#define print3(e,f,g) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<","<<#f<<"=\""<<(f)<<"\""<<","<<#g<<"=\""<<(g)<<"\""<<endl
#define print4(e,f,g,h) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<","<<#f<<"=\""<<(f)<<"\""<<","<<#g<<"=\""<<(g)<<"\""<<","<<#h<<"=\""<<(h)<<"\""<<endl
#define print5(e,f,g,h,j) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<","<<#f<<"=\""<<(f)<<"\""<<","<<#g<<"=\""<<(g)<<"\""<<","<<#h<<"=\""<<(h)<<"\""<<","<<#j<<"=\""<<(j)<<"\""<<endl
#endif
#ifndef LOCAL
#define print(e)
#define print2(e,f)
#define print3(e,f,g)
#define print4(e,f,g,h)
#define print5(e,f,g,h,j)
#endif
void input(){
}
void solve(){
}
int main(){
#ifdef LOCAL
printf(" debug opened!\n");
freopen(".txt","r",stdin);
#endif
input();
solve();
return 0;
}
测评机:花里胡哨
第一题:奶酪
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define print(e) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<e<<"\""<<endl
#define print2(e,f) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<e<<"\""<<","<<#f<<"=\""<<f<<"\""<<endl
#define print3(e,f,g) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<e<<"\""<<","<<#f<<"=\""<<f<<"\""<<","<<#g<<"=\""<<g<<"\""<<endl
#define print4(e,f,g,h) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<e<<"\""<<","<<#f<<"=\""<<f<<"\""<<","<<#g<<"=\""<<g<<"\""<<","<<#h<<"=\""<<h<<"\""<<endl
#define print5(e,f,g,h,j) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<e<<"\""<<","<<#f<<"=\""<<f<<"\""<<","<<#g<<"=\""<<g<<"\""<<","<<#h<<"=\""<<h<<"\""<<","<<#j<<"=\""<<j<<"\""<<endl
#endif
#ifndef LOCAL
#define print(e)
#define print2(e,f)
#define print3(e,f,g)
#define print4(e,f,g,h)
#define print5(e,f,g,h,j)
#endif
#define maxHoleNum 1000
int dataNumRemain,//T<=20
holeNum;//n<=1000
unsigned long long height,radius;//1<=h,r<=1e10
struct hole{
long long x;
long long y;
long long z;
int father;
int connection;
/*
-1:top
0:non
1:bottom
*/
};
bool connected(hole A,hole B){
return 4*radius*radius>=(A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)+(A.z-B.z)*(A.z-B.z);
}
hole holes[maxHoleNum];
void input()
{
scanf("%d%lld%lld",&holeNum,&height,&radius);
print3(holeNum,height,radius);
for(int i=0;i<holeNum;i++){
scanf("%lld%lld%lld",&holes[i].x,&holes[i].y,&holes[i].z);
if(holes[i].z-radius<=0)
holes[i].connection=1;
else if(holes[i].z+radius>=height)
holes[i].connection=-1;
else
holes[i].connection=0;
holes[i].father=i;
print5(holes[i].x,holes[i].y,holes[i].z,holes[i].connection,holes[i].father);
}
}
void solve(){
int excMd;
for(int i=0;i<holeNum;i++)
for(int j=0;j<holeNum;j++){
if(i==j)continue;
print2(i,j);
print5(holes[i].x,holes[i].y,holes[i].z,holes[i].connection,holes[i].father);
print5(holes[j].x,holes[j].y,holes[j].z,holes[j].connection,holes[j].father);
if(connected(holes[i],holes[j]))
{
if((holes[i].connection==-1&&holes[j].connection==0)||(holes[j].connection==-1&&holes[i].connection==0))
for(int pointer=holes[i].father;pointer!=i;pointer=holes[pointer].father)holes[j].connection=holes[i].connection=-1;
else if((holes[i].connection==1&&holes[j].connection==0)||(holes[j].connection==1&&holes[i].connection==0))
for(int pointer=holes[i].father;pointer!=i;pointer=holes[pointer].father)holes[j].connection=holes[i].connection=1;
else if(holes[i].connection==-1&&holes[j].connection==1)
{
printf("Yes\n");
return;
}
for(int pointer=holes[i].father;pointer!=i;pointer=holes[pointer].father)
if(pointer==j)
goto a;
excMd=holes[i].father;
holes[i].father=holes[j].father;
holes[j].father=excMd;
a: continue;
}
}
printf("No\n");
} int main()
{
#ifdef LOCAL
printf(" debug opened!\n");
freopen("cheese.txt","r",stdin);
#endif
for(scanf("%d",&dataNumRemain);dataNumRemain>0;dataNumRemain--)
{
input();
solve();
}
return 0;
}
过样例后爆0
第二题没调出来
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#ifdef LOCAL
#define print(e) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<endl
#define print2(e,f) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<","<<#f<<"=\""<<(f)<<"\""<<endl
#define print3(e,f,g) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<","<<#f<<"=\""<<(f)<<"\""<<","<<#g<<"=\""<<(g)<<"\""<<endl
#define print4(e,f,g,h) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<","<<#f<<"=\""<<(f)<<"\""<<","<<#g<<"=\""<<(g)<<"\""<<","<<#h<<"=\""<<(h)<<"\""<<endl
#define print5(e,f,g,h,j) cout<<" DebugMSG:In line:"<<__LINE__<<","<<#e<<"=\""<<(e)<<"\""<<","<<#f<<"=\""<<(f)<<"\""<<","<<#g<<"=\""<<(g)<<"\""<<","<<#h<<"=\""<<(h)<<"\""<<","<<#j<<"=\""<<(j)<<"\""<<endl
#endif
#ifndef LOCAL
#define print(e)
#define print2(e,f)
#define print3(e,f,g)
#define print4(e,f,g,h)
#define print5(e,f,g,h,j)
#endif
#define maxConnection 1005
#define inf 1e10
int nodeNum,//n<=12
connectionNum,//m<=1000
firstRoom;
long long opened;
struct connection{
int weight;
int a;
int b;
int id;
bool open;
connection()
{
open=false;
}
long long cost(int hash);
};
connection connections[1005];
long long shortestWayRoomLength(int room,bool needOpened,int colorHash){//0:unvisited,1:visited
long long minWay=inf;
for(int i=0;i<connectionNum;i++){
if((!connections[i].open)&&needOpened)continue;
if(connections[i].a==room&&connections[i].b==firstRoom)return 2;
if(connections[i].a==room&&!(colorHash>>connections[i].b))minWay=min(minWay,shortestWayRoomLength(connections[i].b+1,needOpened,colorHash+(1<<room)));
if(connections[i].b==room&&!(colorHash>>connections[i].a))minWay=min(minWay,shortestWayRoomLength(connections[i].a+1,needOpened,colorHash+(1<<room)));
}
return minWay;}
long long connection::cost(int hash){
if((opened>>a)&1&&(opened>>b)^1){//only a open
return shortestWayRoomLength(a,true,hash)*weight;
}
else if((opened>>a)^1&&(opened>>b)&1)
{//only b open
return shortestWayRoomLength(b,true,hash)*weight;
}
else
return -1;
}
void input(){
scanf("%d%d",&nodeNum,&connectionNum);
for(int i=0;i<connectionNum;i++){
scanf("%d%d%d",&connections[i].a,&connections[i].b,&connections[i].weight);
connections[i].id=i;
}
}
long long getMinTotalCost(int colorHash){//0:unvisited,1:visited
long long ans=inf;
if(colorHash==(1<<(nodeNum+1))-1)return 0;
for(int i=0;i<nodeNum;i++){
if(colorHash>>i)continue;
for(int j=0;j<connectionNum;j++){
if(colorHash+(1<<i)<=(1<<(nodeNum+1))-1)
ans=min(ans,getMinTotalCost(colorHash+(1<<i))+connections[j].cost(colorHash));
print5(colorHash>>i,ans,colorHash,i,j);
}
}
return ans;
}
void solve(){
long long minTotalCost=inf;
for(int i=0;i<nodeNum;i++){
firstRoom=i;
print(firstRoom);
minTotalCost=min(minTotalCost,getMinTotalCost(1<<i));
}
printf("%lld",minTotalCost);
}
int main(){
#ifdef LOCAL
printf(" debug opened!\n");
freopen("treasure.txt","r",stdin);
#endif
input();
solve();
return 0;
}