Regionals 2014 >> Europe - Central >> 6934 - Good morning!

6934 - Good morning!

题目:

题目大意:按键只能向右或者向下,给出一个数字,问能按出的数字中与其最接近的数字是什么。

题目思路:暴力

题目链接:6934 - Good morning!

以下是代码:

#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
vector <int> a;

void solve()
{
    for (int i = 0; i < 10; i++)
    {
        a.push_back(i);
    }
    a.push_back(12);a.push_back(200);a.push_back(177);a.push_back(70);a.push_back(170);
    a.push_back(11);a.push_back(22);a.push_back(33);a.push_back(44);a.push_back(55);
    a.push_back(66);a.push_back(77);a.push_back(88);a.push_back(99);a.push_back(111);   
    a.push_back(13);a.push_back(16);a.push_back(19);a.push_back(23);a.push_back(26);
    a.push_back(29);a.push_back(36);a.push_back(39);a.push_back(69);a.push_back(123);
    a.push_back(126);a.push_back(129);a.push_back(136);a.push_back(139);a.push_back(169);
    a.push_back(113);a.push_back(133);a.push_back(166);a.push_back(199);a.push_back(116);
    a.push_back(119);a.push_back(15);a.push_back(25);a.push_back(56);a.push_back(59);
    a.push_back(125);a.push_back(156);a.push_back(159);a.push_back(115);a.push_back(18);
    a.push_back(28);a.push_back(58);a.push_back(89);a.push_back(128);a.push_back(158);
    a.push_back(118);a.push_back(188);a.push_back(10);a.push_back(20);a.push_back(50);
    a.push_back(80);a.push_back(120);a.push_back(150);a.push_back(180);a.push_back(110);
    a.push_back(100);a.push_back(14);a.push_back(45);a.push_back(46);a.push_back(49);   
    a.push_back(145);a.push_back(146);a.push_back(149);a.push_back(114);a.push_back(144);
    a.push_back(48);a.push_back(148);a.push_back(40);a.push_back(140);a.push_back(17);
    a.push_back(47);a.push_back(78);a.push_back(79);a.push_back(147);a.push_back(117);
    a.push_back(178);a.push_back(179);a.push_back(189);a.push_back(155);a.push_back(112);
    a.push_back(122);
    sort(a.begin(),a.begin() + 96); 
}
int main(){
    int t;
    cin >> t;
    solve();
    while(t--)
    {
        int k;
        cin >> k;
        int poi = 0;
        for (int i = 0; i < 96; i++)
        {
            if (a[i] > k)
            {
                poi = i;
                break;
            }
        }
        int d1 = a[poi - 1] - k;
        int d2 = a[poi] - k;
        if (abs(d1) < abs(d2)) cout << a[poi - 1] << endl;
        else    cout << a[poi] << endl;
    } 
    return 0;
}

你可能感兴趣的:(central,Regionals,6934)