今天有点无聊,上来求一算法!!
回8楼码农007的帖子
论坛难得这么热闹,忍不住手痒,版主写了php版本,于是写个C版本int的..
#includeint middle(int a,int b,int c){ long long la=a; long long lb=b; long long lc=c; long long f1=(lc-la)>>63&0x1; long long f2=(lb-lc)>>63&0x1; long long f3=1^(f1+f2); return f1*a+f2*b+f3*c;}int main(){ int a,b,c; while(~scanf('%d%d%d',&a,&b,&c)) { printf('%d\n',middle(a,b,c)); }}转为longlong 是为了防止溢出测试如下:5 10 355 10 885 10 1310-2000000000 2000000000 -1000000000-1000000000-2000000000 2000000000 10000000001000000000-2000000000 2000000000 -2000000001-2000000000-2000000000 2000000000 20000000012000000000只是感觉这样效率很低...
赞0
踩0