[NHZXOI2017]2016NOIP普及组复赛题解

  用了两天的中午时间做了一套今年的普及组复赛试题结果测出来分数只有两百!(第三题洛谷全过,lemon却显示编译错误,奇了怪了微笑

第一题  买铅笔

考查知识点:数学

解题思路:把每个产品买够n支笔时的钱算出来,选取最小的。

代码:

#include <iostream>
#include <cstdio>
using namespace std;
char ch;
int getnum()
{
	ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar());
	int ret = 0;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) ret = ret * 10 + ch - 48;
	return ret;
}
int i,k,a,b,minnum;
int main()
{
	k = getnum(); 
	minnum = 1 << 30;
	for (i = 1; i <= 3; i++)
	{
		a = getnum(); b = getnum();
		if (a < k) 
		  if (k % a != 0) b = b * (k / a + 1); else b = b * (k / a);
		if (b < minnum) minnum = b;
	}
	printf("%d",minnum);
	return 0;
}

第二题:回文日期

考察知识点:日期模拟,判断回文数

题解

①:设置三个变量,分别模拟年、月、日。

    注意当月有多少天?当年有多少天?

②:判断回文数,把原来的数翻转然后跟原来的数判断是否相同即可

代码:

#include <iostream>
#include <cstdio>
using namespace std;
char ch;
int date[4],arrived_date,num,ans;
int getnum()
{
	ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar());
	int ret = 0;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) ret = ret * 10 + ch - 48;
	return ret;
}
void iread()
{
	int temp,i;
	temp = getnum();
	date[1] = temp / 10000; temp %= 10000;
	date[2] = temp / 100; temp %= 100;
	date[3] = temp;
	arrived_date = getnum();
}
bool check()
{
	int i,x = 0,y = 0,temp;
	x = date[1] * 10000 + date[2] * 100 + date[3];
	temp = x;
	for (i = 8; i >= 1; i--)
	{
		y = y * 10 + temp % 10; temp /= 10;
	}  
	if (x == y) return true; else return false;
}
bool check_arrived()
{
	int i,x = 0,y = 0;
	x = date[1] * 10000 + date[2] * 100 + date[3];
	if (x <= arrived_date) return false; else return true;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值