这个引用好精髓。
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <map> 5 #include <set> 6 #include <algorithm> 7 #include <fstream> 8 #include <cstdio> 9 #include <cmath> 10 #include <stack> 11 #include <queue> 12 using namespace std; 13 const double Pi=3.14159265358979323846; 14 typedef long long ll; 15 const int MAXN=5000+5; 16 const int dx[5]={0,0,0,1,-1}; 17 const int dy[5]={1,-1,0,0,0}; 18 const int INF = 0x3f3f3f3f; 19 const int NINF = 0xc0c0c0c0; 20 const ll mod=1e9+7; 21 22 bool solve(int &w) 23 { 24 int w1,w2,d1,d2; 25 cin>>w1>>d1>>w2>>d2; 26 bool b1=true,b2=true; 27 if(!w1) b1=solve(w1); 28 if(!w2) b2=solve(w2); 29 w=w1+w2; 30 return (b1&&b2&&(d1*w1==d2*w2)); 31 } 32 33 34 int main() 35 { 36 int t;cin>>t; 37 while(t--) 38 { 39 int w; 40 if(solve(w)) cout <<"YES\n"; 41 else cout <<"NO\n"; 42 if(t) cout<<"\n"; 43 } 44 return 0; 45 }