来吧!开始刷题吧~!在刷题的世界里挖呀挖呀挖,挖出全新的思维方式O(∩_∩)O。
老规矩洛谷走起,链接:https://www.luogu.com.cn/
目录
2.P5709 【深基2.习6】Apples Prologue / 苹果和虫子
1.P5707 【深基2.例12】上学迟到
链接:https://www.luogu.com.cn/problem/P5707
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int s,u,t; //路程s,速度u
cin>>s>>u;
if(s%u==0){ //判断路程s除速度u,若为整数直接除
t=s/u;
}
else{ //否则需要增加1,也就是出门提前1分钟
t=s/u+1;
}
t = t+10; //垃圾分类总时间10分钟
int t_ans;
t_ans = 8*60+24*60; //总分钟数
t_ans = t_ans-t; //减需要的时间,为多久出门的时间
if(t_ans>=24*60){ //判断是否在前一天出门
t_ans = t_ans-24*60;
}
int a,b;
b = t_ans%60; //提前出门的小时
a = t_ans/60; //提前出门的分钟
if(b<10){ //判断分钟是否小于10,是否补0
if(a<10){
cout<<"0"<<a<<":0"<<b<<endl;
}
else{
cout<<a<<":0"<<b<<endl;
}
}
else{
if(a<10){
cout<<"0"<<a<<":"<<b<<endl;
}
else{
cout<<a<<":"<<b<<endl;
}
}
system("pause");
}
2.P5709 【深基2.习6】Apples Prologue / 苹果和虫子
链接:https://www.luogu.com.cn/problem/P5709
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int m,t,s,ans; //m苹果个数 t吃一个苹果时间 s总过去时间
cin>>m>>t>>s;
if(t==0){ //若吃苹果0分钟,则一个不剩
cout<<0<<endl;
return 0;
}
if(t>0){
if(s%t==0){ //若总过去时间s求余吃苹果时间t等于0,表示没有开始吃下一个
cout<<max(m-s/t,0)<<endl; //若吃的苹果数大于总苹果个数m,则没苹果了输出0
}
else{
cout<<max(m-s/t-1,0)<<endl; //若不等于0,表示有一个吃了一半,则需要减掉
}
}
system("pause");
}
3.P5710 【深基3.例2】数的性质
链接:https://www.luogu.com.cn/problem/P5710
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int x,a=0,b=0,c=0,d=0; //a对应小A b对应Uim c对应八尾 d对应正妹
cin>>x;
if(x%2==0){ //满足偶数
if(x>4 && x<=12){ //且满足大于4不高于12
a = 1;
b = 1;
}
else{ //仅满足偶数
b = 1;
c = 1;
}
}
else{ //不满足偶数
if(x>4 && x<=12){ //满足大于4不高于12
b = 1;
c = 1;
}
else{ //都不满足
d = 1;
}
}
cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
system("pause");
}
4.P5711 【深基3.例3】闰年判断
链接:https://www.luogu.com.cn/problem/P5711
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
//闰年:能被4整除不能被100整除,或能被400整除均为闰年
if((n%4==0&&n%100!=0) || n%400==0){
cout<<1<<endl;
}
else{
cout<<0<<endl;
}
system("pause");
}
5.P5712 【深基3.例4】Apples
链接:https://www.luogu.com.cn/problem/P5712
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int x;
cin>>x;
if(x==1 || x==0){
cout<<"Today, I ate "<<x<<" apple."<<endl;
}
else {
cout<<"Today, I ate "<<x<<" apples."<<endl;
}
system("pause");
}
6.P5713 【深基3.例5】洛谷团队系统
链接:https://www.luogu.com.cn/problem/P5713
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
if(n*5 > n*3+11){
cout<<"Luogu"<<endl;
}
else{
cout<<"Local"<<endl;
}
system("pause");
}
7.P5714 【深基3.例7】肥胖问题
链接:https://www.luogu.com.cn/problem/P5714
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
float m,h,BMI;
cin>>m>>h;
BMI = m*1.0 / pow(h,2);//BMI=身高/体重的平方
if(BMI<18.5){
cout<<"Underweight"<<endl;
}
else if(BMI<24){
cout<<"Normal"<<endl;
}
else{
cout<<BMI<<endl;
cout<<"Overweight"<<endl;
}
system("pause");
}
8.P5715 【深基3.例8】三位数排序
链接:https://www.luogu.com.cn/problem/P5715
#include<iostream>
using namespace std;
int main(){
int a,b,c,max,zjz,min;
cin>>a>>b>>c;
if(a>=b && a>=c){ //a最大
max=a;
if(b>=c){
zjz=b; min=c;
}
else{
zjz=c; min=b;
}
}
if(b>=a && b>=c){ //b最大
max=b;
if(a>=c){
zjz=a; min=c;
}
else{
zjz=c; min=a;
}
}
if(c>=b && c>=a){ //c最大
max=c;
if(b>=a){
zjz=b; min=a;
}
else{
zjz=a; min=b;
}
}
cout<<min<<" "<<zjz<<" "<<max<<endl;
system("pause");
}
9.P5716 【深基3.例9】月份天数
链接:https://www.luogu.com.cn/problem/P5716
#include<iomanip>
#include<iostream>
using namespace std;
int main(){
int n,y,t;//n年 y月 t天
cin>>n>>y;
if(y==1||y==3||y==5||y==7||y==8||y==10||y==12)
t=31;
else if(y==4||y==6||y==9||y==11)
t=30;
else if(y==2)
t=28;//平年2月28天
//判断是否为闰年且是否为2月
if((n%400==0||(n%4==0&&n%100!=0))&&y==2)
t=t+1;//闰年2月29天
cout<<t;
return 0;
}
10.P5717 【深基3.习8】三角形分类
链接:https://www.luogu.com.cn/problem/P5717
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int a,b,c,max1,min1,zjz;
cin>>a>>b>>c;
if(a>=b && a>=c){
max1 = a;
if(b>=c){
min1 = c;
zjz = b;
}
else{
min1 = b;
zjz = c;
}
}
else if(b>=a && b>=c){
max1 = b;
if(a>=c){
min1 = c;
zjz = a;
}
else{
min1 = a;
zjz = c;
}
}
if(c>=a && c>=b){
max1 = c;
if(a>=b){
min1 = b;
zjz = a;
}
else{
min1 = a;
zjz = b;
}
}
if(zjz+min1>max1){
if(pow(zjz,2)+pow(min1,2)==pow(max1,2)){
cout<<"Right triangle"<<endl;
return 0;
}
if(pow(zjz,2)+pow(min1,2)>pow(max1,2)){
cout<<"Acute triangle"<<endl;
}
if(pow(zjz,2)+pow(min1,2)<pow(max1,2)){
cout<<"Obtuse triangle"<<endl;
}
if(max1==min1 || max1==zjz || min1==zjz){
cout<<"Isosceles triangle"<<endl;
}
if(min1==max1 && max1==zjz){
cout<<"Equilateral triangle"<<endl;
}
}
else{
cout<<"Not triangle"<<endl;
}
system("pause");
}
11.P1422 小玉家的电费
链接:https://www.luogu.com.cn/problem/P1422
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int x;
float ans;
cin >> x;
if(x<=150){
ans = x*0.4463;
}
else if(x<=400){
ans = 150*0.4463+(x-150)*0.4663;
}
else{
ans = 150*0.4463+250*0.4663+(x-400)*0.5663;
}
printf("%.1f",ans);
return 0;
}
大家刷题开心,有什么疑问可以在下面提问。