連接php
規律題,但須要注意下如何浮點數處理的技巧
ios
#include <iostream> #include <cstring> #include <string.h> #include <cstring> #include <fstream> #include <sstream> #include <vector> #include <cstdlib> #include <cstdio> #include <cmath> using namespace std; #ifdef DEBUG ifstream in; ofstream out; #endif #ifdef DEBUG #define inpath "./in.txt" #define outpath "./out.txt" #define CIN in #define COUT out #else #define CIN cin #define COUT cout #endif int main() { int sec; int idx; int x, y; int cnt, vcnt; #ifdef DEBUG in.open(inpath, ios::in); out.open(outpath, ios::out); if(in.fail()){ cout << "input init fail " << "\n"; return -1; }else{ cout << "input init success " << "\n"; } if(out.fail()){ cout << "output init fail " << "\n"; return -1; }else{ cout << "output init success " << "\n"; } #endif while(CIN >> sec && sec > 0 ){ #ifdef DEBUG cout << sec << endl; #endif idx = (int)floor(sqrt((double)sec) - 1e-9) + 1; if(idx & 0x1){ x = 1; y = idx; }else{ x = idx; y = 1; } cnt = idx*idx - sec; vcnt = idx - 1; #ifdef DEBUG cout << "idx= " << idx << endl; cout << "x= " << x << endl; cout << "y= " << y << endl; cout << "cnt= " << cnt << endl; cout << "vcnt= "<< vcnt << endl; #endif if(idx & 0x1){ while(vcnt > 0 && cnt > 0){ x++; cnt--; vcnt--; } #ifdef DEBUG cout << x << " " << y << endl; cout << "cnt = " << cnt << endl; #endif while(cnt-- > 0) y--; }else{ while(vcnt > 0 && cnt > 0){ y++; cnt--; vcnt--; } while(cnt-- > 0) x--; } COUT << x << " " << y << endl; } return 0; }