{"comment":{"url":"https://api.github.com/repos/huqinwei/algorithm-nowcoder-huawei/comments/16649161","html_url":"https://github.com/huqinwei/algorithm-nowcoder-huawei/commit/e97fc3a3d49b5f6fe39a4fce388523d57e4bcc8f#commitcomment-16649161","id":16649161,"user":{"login":"huqinwei","id":17739377,"avatar_url":"https://avatars.githubusercontent.com/u/17739377?v=3","gravatar_id":"","url":"https://api.github.com/users/huqinwei","html_url":"https://github.com/huqinwei","followers_url":"https://api.github.com/users/huqinwei/followers","following_url":"https://api.github.com/users/huqinwei/following{/other_user}","gists_url":"https://api.github.com/users/huqinwei/gists{/gist_id}","starred_url":"https://api.github.com/users/huqinwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huqinwei/subscriptions","organizations_url":"https://api.github.com/users/huqinwei/orgs","repos_url":"https://api.github.com/users/huqinwei/repos","events_url":"https://api.github.com/users/huqinwei/events{/privacy}","received_events_url":"https://api.github.com/users/huqinwei/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"e97fc3a3d49b5f6fe39a4fce388523d57e4bcc8f","created_at":"2016-03-11T16:52:00Z","updated_at":"2016-03-11T16:52:00Z","body":"/*\r\n递归问题\r\n3个瓶子换1瓶水+1个空瓶子，两个瓶子换1瓶水+0个空瓶子，1个瓶子换0瓶水。\r\nf(1) = 0\r\nf(2) = 1\r\nf(3) = 1\r\nf(4) = f(2)+1    //4个瓶子，其中3个可以换1瓶水+1个空瓶，所以是f(2)+1\r\nf(5) = f(3)+1    //3个瓶子换1瓶水+1个空瓶，所以是f(3)+1\r\n...\r\nf(n) = f(n-2)+1 */\r\n#include <iostream>\r\n  \r\nusing namespace std;\r\n  \r\nint f(int n)\r\n{\r\n    if(n==1) return 0;\r\n    if(n==2) return 1;\r\n    return f(n-2)+1;\r\n}\r\n  \r\nint main()\r\n{\r\n    int n;\r\n    while(cin >> n){\r\n        if(n==0)\r\n            break;\r\n        cout<<f(n)<<endl;\r\n    }\r\n    return 0;\r\n}"}}