Created
July 11, 2014 10:59
-
-
Save kdxu/ee4d77ed74f8764055b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<sstream> | |
#include<string> | |
#include<cmath> | |
#include<cstdio> | |
#include<vector> | |
#include<map> | |
#include<set> | |
#include<queue> | |
#include<deque> | |
#include<algorithm> | |
#include<functional> | |
#include<numeric> | |
#define rep(i,b) | |
using namespace std; | |
int main(){ | |
while(1){ | |
int n,r; | |
cin >> r >> n; | |
if(n==0&&r==0)break; | |
bool block[20][20]; | |
for(int i=0;i<20;i++){ | |
for(int j=0;j<20;j++){ | |
block[i][j]=false; | |
} | |
} | |
for(int i=0;i<n;i++){ | |
int xl,xr,h; | |
cin >>xl>>xr>>h; | |
for(int j=xl;j<xr;j++){ | |
for(int k=0;k<h;k++){block[j][k]=true;} | |
} | |
} | |
int f=0; | |
for(int i=-r;i<r;i++){ | |
if(block[i][0]==false){f=1;cout << "0.0000" <<endl;} | |
} | |
if(f==1){continue;} | |
vector < pair<int,int> > kado; | |
/* | |
for(int i=-1;i<1;i++){ | |
for(int j=20;j>0;j--){ | |
if(block[i][j]==true){ | |
kado.push_back((pair<int,int>(0,j+1))); | |
} | |
} | |
}*/ | |
for(int i=0;i<r;i++){ | |
for(int j=20;j>0;j--){ | |
if(block[i][j]==true){ | |
kado.push_back( (pair<int,int>(i,j+1))); | |
} | |
} | |
} | |
for(int i=-1;i>-r;i--){ | |
for(int j=20;j>0;j--){ | |
if(block[i][j]==true){ | |
kado.push_back( pair<int,int>(i,j+1)); | |
} | |
} | |
} | |
float result = 20+r; | |
for(int i=0;i<kado.size();i++){ | |
float y = r*r-((kado[i].first)*(kado[i].first)); | |
y = sqrt(y); | |
//printf("%f",kado[i].second-y+r );cout <<endl; | |
result=min(result,kado[i].second-y+r); | |
} | |
printf("%.4f",result); | |
cout << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment