CF Theatre Square(注意强制类型转换)

Theatre Square in the capital city of Berland has a rectangular shape with the size
n×m meters. On the occasion of the city’s anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size
a×a .
What is the least number of flagstones needed to pave the Square? It’s allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It’s not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.

输入格式

The input contains three positive integer numbers in the first line: n,m and a,范围 1e9内

输出格式

Write the needed number of flagstones.

输入输出样例

输入 #1 复制
6 6 4
输出 #1 复制
4

本题有两个坑
1: 强制类型转换
2: 分配律的应用

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int main()
{
    int count = 0;
    ll n, m, a;
    scanf("%lld %lld %lld",&n,&m,&a);
    count = ll(ceil(n / (double)a) * ceil(m / (double)a));
    printf("%d\n",count);
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, here is an example implementation in Java: ```java import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; public class Student { private String name; private ArrayList<String> hobbies; public Student(String name, ArrayList<String> hobbies) { this.name = name; this.hobbies = hobbies; } public String getName() { return name; } public ArrayList<String> getHobbies() { return hobbies; } public static void main(String[] args) { ArrayList<Student> students = new ArrayList<>(); try (BufferedReader br = new BufferedReader(new FileReader("students.txt"))) { String line; while ((line = br.readLine()) != null) { String[] parts = line.split(","); String name = parts[0]; ArrayList<String> hobbies = new ArrayList<>(); for (int i = 1; i < parts.length; i++) { hobbies.add(parts[i]); } students.add(new Student(name, hobbies)); } } catch (IOException e) { System.err.format("IOException: %s%n", e); } Collections.sort(students, (s1, s2) -> s1.getName().compareTo(s2.getName())); for (Student student : students) { System.out.println(student.getName() + ": " + student.getHobbies()); } } } ``` This code reads the student data from a file called "students.txt" (in the same directory as the Java file), creates a `Student` object for each line, and stores them in an `ArrayList`. It then sorts the list by student name using a lambda expression, and finally prints out each student's name and hobbies using a `for` loop.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值