题解【洛谷P5315】头像上传

本题就是按照题目模拟, 只是要注意一些细节问题。

Wrong Answer的主要有以下2个问题:

  • 注意这句话:

在图片上传前,系统会对图片进行如下处理:如果图片的任何一边长度超过了 G ,那么系统会不断地对图片的长宽同时减半(向下取整),直至两边长度 ≤G 为止。

是长宽同时减半,而不是只减半一条边!

  • 注意输出的每个单词的首字母都要大写!

注意了以上2点后,只要不出什么意外,就都能AC了!

附上AC代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cstring>//头文件准备

using namespace std;//使用标准名字空间

inline int gi()//快速读入
{
	int f = 1, x = 0;
	char c = getchar();
	
	while (c < '0' || c > '9')
	{
		if (c == '-')
			f = -1;
		c = getchar();
	}
	
	while (c >= '0' && c <= '9')
	{
		x = x * 10 + c - '0';
		c = getchar();
	}
	
	return f * x;
}

int n, l, g, w, h;//n, l, g的含义见题意,w, h分别为图片的长和宽

int main()
{
	n = gi(), l = gi(), g = gi();//输入
	
	while (n--)//处理n组数据
	{
		w = gi(), h = gi();//输入图片的长和宽
		
		while (w > g)//当长不符合要求时
		{
			w = w >> 1, h = h >> 1;//长宽同时除以2
		}
		
		while (h > g)//当宽不符合要求时
		{
			w = w >> 1, h = h >> 1;//长宽同时除以2
		}
		
		if (w < l || h < l) puts("Too Young");//如果有任何一边长度<l,就输出“Too Young”
		else if (w == h) puts("Sometimes Naive");//如果是正方形,就输出“Sometimes Naive”
		else puts("Too Simple");//否则就输出“Too Simple”
	}
	
	return 0;//完美结束
}
posted @ 2019-04-20 22:29  csxsi  阅读(714)  评论(0编辑  收藏  举报