codeforces 1A-Theatre Square

枚举判断一下就行了,刚开始的时候用int保存结果,然后wa了一次。换成long long 就对了

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
#include<set>
#include<vector>
#include<cstdio>
#include<stack>
#include<sstream>
#include<cstring>
using namespace std;
const int MAX=100005;
typedef long long ll;
int main()
{
    long double n,m,a;
    cin>>n>>m>>a;
    if(a<m&&a<n)
    {
        ll r1=ceil(m/a);
        ll r2=ceil(n/a);
        cout<<r1*r2<<endl;
    }
    else if(a>=m&&a<n)
    {
        ll r1=ceil(n/a);
        cout<<r1<<endl;
    }
    else if(a<m&&a>=n)
    {
        ll r1=ceil(m/a);
        cout<<r1<<endl;
    }
    else
        cout<<"1"<<endl;
    return 0;
}

更简单的方法:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
#include<set>
#include<vector>
#include<cstdio>
#include<stack>
#include<sstream>
#include<cstring>
using namespace std;
const int MAX=100005;
typedef long long ll;
int main()
{
    long double n,m,a;
    cin>>n>>m>>a;
    ll r1=ceil(m/a);
    ll r2=ceil(n/a);
    cout<<r1*r2<<endl;
    return 0;
}
保证不小于n和m就行了

你可能感兴趣的:(算法,CF)