[topcoder] EllysNumberGuessing
2024-09-21 08:51:48
http://community.topcoder.com/stat?c=problem_statement&pm=12975
简单题
#include <cstdlib>
#include <vector>
using namespace std; class EllysNumberGuessing {
public:
int getNumber(vector <int> guesses, vector <int> answers) {
const int LIMIT = 1000000000;
int N = guesses.size();
int res = -2; // not find
vector<int> options{ guesses[0] + answers[0], guesses[0] - answers[0]};
for (int i = 0; i < options.size(); i++) {
int x = options[i];
bool valid = (x >= 1 && x <= LIMIT);
for (int j = 1; j < N; j++) {
valid = valid && (abs(guesses[j] - x) == answers[j]);
}
if (valid) {
if (res == -2) {
res = x;
} else {
res = -1;
}
}
}
return res;
} };
最新文章
- Cache-Aside Pattern(缓存模式)
- Windows Phone App的dump文件实例分析- System.ExecutionEngineException
- 各种Linux发行版本优缺点对比[转]
- js部分---数组及练习题;
- http://www.cnblogs.com/flyoung2008/archive/2013/08/11/3251148.html
- 8天学通MongoDB——第八天 驱动实践
- Sigar.jar获取系统信息
- oracle 使用sql获取数据库表,表的字段
- java 笔试
- [编织消息框架][设计协议]bit基础
- Hadoop2.7.5+Hbase1.4.0完全分布式
- 如何设置select和option的文字居中?
- python数据类型:字典dict常用操作
- springboot application.properties 常用完整版配置信息
- softmax 损失函数求导过程
- Codeforces962F Simple Cycles Edges 【双连通分量】【dfs树】
- canutils上板测试问题记录
- 源码安装 odoo12 -- 问题记录
- spring与activemq(三种消息监听方式)
- ROS 进阶学习笔记(12) - Communication with ROS through USART Serial Port