Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我是SB,超级SB.....WA的同学看看,你是不是也和我犯了一样SB的错误这道题用除法基本是没有问题的,注意四个if-else分支,基本就没问题了。大家请看我两个版本的差异: 错误版本: #include <iostream> using namespace std; int main() { int a,b,i,j,n,l,r; cin >> n; while(n--) { cin >> a >> b; l=r=0; while(!(a==1 && b==1)) { //直接回溯到上一个转折节点 if(a>b) { l += (a/b); if(a%b==0) { l--; } a = (a%b); if(b == 1) { a=1; } } else { r += (b/a); if(b%a==0) { r--; } b = (b%a); if(a == 1) { b=1; } } } j=1; cout << "Scenario #" << j++ << ":" << endl; cout << l << " " << r << endl << endl; } return 0; } 正确版本: #include <iostream> using namespace std; int main() { int a,b,i,j,n,l,r; cin >> n; j=1; while(n--) { cin >> a >> b; l=r=0; while(!(a==1 && b==1)) { //直接回溯到上一个转折节点 if(a>b) { l += (a/b); if(a%b==0) { l--; } a = (a%b); if(b == 1) { a=1; } } else { r += (b/a); if(b%a==0) { r--; } b = (b%a); if(a == 1) { b=1; } } } cout << "Scenario #" << j++ << ":" << endl; cout << l << " " << r << endl << endl; } return 0; } 看到为什么WA了么??? 我也就在这里墨迹了1个多小时,WA了10多次而已.......恩,我是SB。大家尽情的BS我把~ Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator