Bob's Problem

本文探讨了如何解决特定数学问题,通过枚举法在有限范围内寻找满足条件的正整数解,深入理解算法在实际问题中的应用。
题目描述

Bob今天碰到一个问题,他想知道x3+y3 = c 是否存在正整数解?

输入

第一行是一个整数K(K≤20000),表示样例的个数。 以后每行一个整数c(2≤c≤109)

输出

每行输出一个样例的结果,如果存在,输出“Yes”,否则输出“No”。(引号不用输出)

样例输入
2
28
27

样例输出
Yes
No

题解:这个数学题目,只能通过枚举。STL set中可以保存数字出现没有。
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
int f[3010],t=0,i,j,n,T;
int main()
{
	set<int> st;
	for (i=1;i<1010;i++)
		f[t++]=i*i*i;
	for (i=0;i<t;i++)
		for (j=1;j<t;j++)
			st.insert(f[i]+f[j]);
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		int k=st.count(n);
		if (k) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


Problem Statement Last year, Glasgow College held the Kelvin Bicentenary Programming Competition to celebrate the life and legacy of Lord Kelvin. As part of the challenge, each of the n participants submitted their programs to control a robot to achieve the highest possible score, in the shortest possible time. The final ranking is based on two main metrics: the score s and the time t spent solving the task. The submission of each participant is evaluated as follows: • s: The final score the participant’s program achieved, representing how well it performed on the task (higher means better). • t: The time that the participant submit their programs (earlier means better). The competition begins at 14:00. The ranking criteria are three-fold: 1. The participants are first sorted by s in descending order. 2. If two participants have the same score s, they are then sorted by t in ascending order. 3. If two participants have the same score s and the same time t, they are then sorted by their name in lexicographic order. Your program is required to input the name, score s, and time t of each participant. The program should then sort the participants following the ranking criteria and output the final ranking of participants by their names only. Constraint • For 20% of the test cases, n ≤ 100; For 60% of the test cases, n ≤ 300; For 100% of the test cases, n ≤ 1000. • 10000 ≤ s ≤200000, 14:00 ≤ t ≤ 17:00. • You are NOT allowed to use qsort function to complete the lab exercises. This will be detected in the structure test. If you fail to pass the structure test, the logic test will not be executed. Input The input contains n +1 lines. • The first line contains an integer n which represents the number of participants. • Each of the following n lines contains a string (the participant’s name) and an integer s and a time t (representing the score and time for that participant). 6 Handout 3 UESTC 1005- Introductory Programming Output Print the names of the participants in the final ranking order, one name per line.Explanation Recall the ranking criteria: participants are first sorted by their score s in descending order. If two participants have the same score, they are sorted by their time t in ascending order. If two participants have the same score and time, they are sorted by their name. • Alice and Bob both have a score of 74,287, but Alice ranks higher because she took less time (as 16:16 < 16:43 ). • David and Charlie both have a score of 13,864 and the same time 15:00, but Charlie ranks higher because his name ranks higher in the lexicographic order. • Everanksfirst with the highest score of 79,874 (so her time does not need to be considered).Base Code #include <stdio.h> //Define your structure first struct { //TODO } Record; // Then your program. Remember to define helper functions int main() { //TODO }
11-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值