http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E

题目大意:Given, n, count the number of solutions to the equation x+2y+2z=n, where x,y,z,n are non negative integers.
解题思路:只对一个枚举由此推算出另外两个的种类,千万不要都枚举!!!

 

#include<iostream>
#include<fstream>
#include<string>
#include<string.h>
using namespace std;
int main(){
    for(long long int n;cin>>n;){
        long long int y,sum=0;
        for(y=0;y<=n/2;y++){
            sum+=(n-2*y)/2+1;
        }
        cout<<sum<<'\n';
    }
}
View Code

 

相关文章:

  • 2021-07-20
  • 2022-02-19
  • 2022-12-23
  • 2021-12-18
  • 2021-07-31
  • 2021-12-24
  • 2022-02-21
  • 2022-12-23
猜你喜欢
  • 2021-07-10
  • 2021-10-12
  • 2022-12-23
  • 2021-11-20
  • 2021-06-07
  • 2021-06-12
相关资源
相似解决方案