标签:io os for sp bs as c++ ios return
清楚原理后很简单
#include<iostream> using namespace std; int abs(int a) { return (a>=0)?a:-a; } int max(int a,int b) { return (abs(a)>=abs(b))?abs(a):abs(b); } int foo(int x,int y) { //int u; int a=abs(x); int b=abs(y); int t=max(a,b); int v=(2*t-1)*(2*t-1); int u=v; if(y==-t) { u=u+7*t+x; } else if(x==t) { u=u+t+y; } else if(y==t) { u=u+3*t-x; } else { u=u+5*t-y; } return u; } int main() { // cout<<foo(1,0)<<endl; for(int y=-4;y<=4;++y) { for(int x=-4;x<=4;++x) { cout<<foo(x,y)<<'\t'; } cout<<endl; } system("pause"); return 0; }
标签:io os for sp bs as c++ ios return
原文地址:http://blog.csdn.net/qq_22335577/article/details/40790087