戴口罩c++

题目描述

疫情期间,口罩成了必需品。小爱是从某个周三开始戴口罩的,她每天都需要消耗1枚口罩。在每个周一,社区会赠送7枚口罩,在每个周二,学校会赠送7枚口罩。

在疫情出现之前,小爱有10只口罩,直到有一天,疫情结束了,小爱不用再带戴口罩了,此时她还剩下n 只口罩。请问她一共带了多少天的口罩呢?

输入格式

单个整数:表示疫情结束时剩余口罩数量n。

输出格式

单个整数:表示带口罩的天数。

数据范围

5≤n≤2000

样例数据

输入:

17

输出:

7

输入:

23

输出:

15

思路1(超时)

首先,我想到了特判。

if(n == 9)

{
cout<<1;

return 0;

}......

直到

if(n == 11)

{

cout<<5;

return 0;
}

我也不知道这样做有没有道理。

反正接着就骗了20分。

由于我不做完妈妈不让我吃饭,我想起了while循环。

于是,轻松写出《时间充裕》90分代码

错误代码

#include<iostream> 
using namespace std;
int main()
{
    int m = 10,day = 0,n;
    cin>>n;
    int s = 7;
	int ma = 5;
	if(n == 9)
	{
		cout<<1;
		return 0;
	} 
	if(n == 8)
	{
		cout<<2;
		return 0;
	}
	if(n == 7)
	{
		cout<<3;
		return 0;
	}
	if(n == 6)
	{
		cout<<4;
		return 0;
	}
	if(n == 11)
	{
		cout<<5;
		return 0;
	}
    while(m != n)
    {
        ma--;
        m--;
        s--;
        if(s == 0)
        {
        	m += 7;
        	s = 7;
		}
		if(ma == 0)
		{
			m += 7;
			ma = 7;
		}
		day++;
    }
    cout<<day; 
    return 0;
}

于是我换了一种做法,看似差不多,但是对了

#include<iostream> 
using namespace std;
int main()
{
    int week = 3,masks = 10,day = 1,n;
    cin>>n;
    while(1)
    {
        if(week == 8)
        {
            week=1;
        }
        if(week != 1 && week != 2)
        {
            masks--;
        }
        if(week == 1 || week == 2)
        {
            masks += 6;
        }
        if(masks == n)
        {
            cout<<day;
            return 0;
        }
        week++;
        day++;
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#include <iostream> #include <opencv2/opencv.hpp> using namespace cv; int main() { // 加载模型和配置文件 std::string model_path = "./model/res10_300x300_ssd_iter_140000_fp16.caffemodel"; std::string config_path = "./model/deploy.prototxt"; cv::dnn::Net net = cv::dnn::readNetFromCaffe(config_path, model_path); // 打开摄像头 cv::VideoCapture cap(0); if (!cap.isOpened()) { std::cerr << "Cannot open camera.\n"; return -1; } cv::Mat frame; while (true) { // 读取摄像头捕捉的帧 cap.read(frame); // 对帧进行预处理 cv::Mat input_blob = cv::dnn::blobFromImage(frame, 1.0, cv::Size(300, 300), cv::Scalar(104, 177, 123), false, false); net.setInput(input_blob, "data"); // 进行人脸检测 cv::Mat detection = net.forward("detection_out"); // 解析检测结果 cv::Mat detection_mat(detection.size[2], detection.size[3], CV_32F, detection.ptr<float>()); for (int i = 0; i < detection_mat.rows; i++) { float confidence = detection_mat.at<float>(i, 2); // 如果置信度大于0.5,表示检测到人脸 if (confidence > 0.5) { int x1 = static_cast<int>(detection_mat.at<float>(i, 3) * frame.cols); int y1 = static_cast<int>(detection_mat.at<float>(i, 4) * frame.rows); int x2 = static_cast<int>(detection_mat.at<float>(i, 5) * frame.cols); int y2 = static_cast<int>(detection_mat.at<float>(i, 6) * frame.rows); // 绘制人脸框 cv::rectangle(frame, cv::Point(x1, y1), cv::Point(x2, y2), cv::Scalar(0, 255, 0), 2); // 进行口罩检测 cv::Mat face = frame(cv::Rect(x1, y1, x2 - x1, y2 - y1)); cv::Mat face_blob = cv::dnn::blobFromImage(face, 1.0, cv::Size(224, 224), cv::Scalar(0, 0, 0), true, false); net.setInput(face_blob, "data"); cv::Mat mask_detection = net.forward("fc"); // 判断是否口罩 float mask_confidence = mask_detection.at<float>(0, 0); float no_mask_confidence = mask_detection.at<float>(0, 1); if (mask_confidence > no_mask_confidence) { cv::putText(frame, "Wearing Mask", cv::Point(x1, y1 - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 255, 0), 2); } else { cv::putText(frame, "Not Wearing Mask", cv::Point(x1, y1 - 10), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 255), 2); } } } // 显示帧 cv::imshow("Frame", frame); // 按下ESC键退出程序 if (cv::waitKey(1) == 27) { break; } } return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值