牛客618824号:我只看了一下题 说一下我的思路 应该是可以在常数时间内计算出来的 这么大的数靠暴力显然不合理 假设位置在右边(正数)我们先一直向右走
找到第一个大于x处时并且需要差值为偶数的 这样选取这个差值的一半的值向左走一步就可以了

0 点赞 评论 收藏
分享
米兰的小铁匠114:优雅点只求第一象限的,结果乘以4,就都通过了。那个最大奇约数笔试的时候怎么改都是复杂度太大,结束后自己做了一下,用一种非常吊的方式实现了,欢迎私聊。

0 点赞 评论 收藏
分享
toraoh:不是看不起n^2暴力,但是,下手写之前,估算一下你们写的东西要跑多久,ok?
这里n^2暴力,是25亿,当电脑1秒算2亿吧(i7-4700HQ,全速的结果),那你也得跑12秒,这题时限1秒,怎么想都不应该。

0 点赞 评论 收藏
分享
dimaiyou:你有没有写while()处理多个用例?我去掉了就好了

0 点赞 评论 收藏
分享
Stupidhod:#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main_mountain() {
long n = 0, m = 0;
vector<pair<long, long>> nums;
while (cin>>n>>m) {
nums.clear();
long d, h;
for (int i = 0; i < m; ++i) {
cin >> d >> h;
nums.push_back(make_pair(d, h));
}
sort(nums.begin(), nums.end(), [](const pair<long, long>& a, const pair<long, long>& b) {
return a.first < b.first;
});
long highest = 0;
bool imp = false;
long diffd = 0;
long diffh = 0;
long more = 0;
for (int i = 0; i < m - 1; ++i) {
diffd = nums[i + 1].first - nums[i].first;
diffh = abs(nums[i + 1].second - nums[i].second);
if (diffh> diffd) {
cout << "IMPOSSIBLE" << endl;
imp = true;
break;
}
more = max(nums[i + 1].second, nums[i].second);
highest = max(highest, (diffd - diffh) / 2 + more);
}
highest = max(highest, nums[nums.size() - 1].second + n - nums[nums.size() - 1].first);
highest = max(highest, nums[0].second - 1 + nums[0].first);
if (!imp) {
cout << highest << endl;
}
}
return 0;
}

0 点赞 评论 收藏
分享
2016-08-17 21:06
天津大学 算法工程师 LambdaZJU:#include <iostream>
#include <vector>
#include <deque>
#include <queue>
using namespace std;
// 2 1 3
// 1 3 2,输出1
// 3 2
// 2 3,输出2
// 3
// 3,输出3
// 逆向过程:
// 3
// 3
// 2 3,把2插到队头
// 3 2,把队尾3插到队头
// 1 3 2,把1插到队头
// 2 1 3,把队尾2插到队头
// 通过观察就是:
// k从n~1,依次进行:把k插到队头,把队尾元素插到队头
//得到顺序序列的过程是:
//1、队头pop出来,push进队尾
//2、队头pop出来,打印结果
//举例:
//2 1 3,输入
//1 3 2,队头2pop出来插入队尾
//打印1,队头1pop出来,打印1
//3 2
//2 3,队头3pop出来插入队尾
//打印2,队头2pop出来,打印2
//3
//3,队头3pop出来插入队尾
//打印3,队头3pop出来,打印3
//队列为空,处理完毕
//逆向过程:从n~1依次做如下处理
//1、push元素进队头
//2、队尾元素pop出来,push进队头
//举例:
//3,push3进队头
//3,队尾3pop出来,push3进队头
//23,push2进队头
//32,队尾3pop出来,push3进队头
//132,push1进队头
//213,队尾2pop出来,push2进队头
//处理完毕
int main()
{
int t;
cin >> t;
// queue<int> num;
// while (t--)
// {
// int temp;
// cin >> temp;
// num.push(temp);
// }
while (t--)
{
// while (!num.empty())
// {
// int n;
// n = num.front();
// num.pop();
int n;
cin >> n;
deque<int> q;
for (int i = n; i > 0; i--)
{
q.push_front(i);
int x = q.back();
q.pop_back();
q.push_front(x);
}
for (int i = 0; i < n - 1; i++)
{
cout << q[i] << " ";
}
cout << q[n - 1];
cout << endl;
// }
}
}
被输入输出搞死,一直说没有通过,修改了好多次输入输出

0 点赞 评论 收藏
分享
2016-04-14 14:46
天津大学 算法工程师 :if(mp%10>=2&&bosshp>mp/10*60+51)就先把mp用完,否则用完一开始送的蓝就平砍到boss死。然后在判断boss剩余血是否大于等于120是就攒5个回合能量射两次。这样应该就能求出来了。如果有错误一定要告诉我!!!。。。

0 点赞 评论 收藏
分享
创作者周榜
更多
关注他的用户也关注了: