日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

B-Traveling Salesman Problem[CF-Gym-102134][2016-2017 7th BSUIR Open Programming Contest]

發(fā)布時(shí)間:2023/12/14 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 B-Traveling Salesman Problem[CF-Gym-102134][2016-2017 7th BSUIR Open Programming Contest] 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

原題傳送門


題面

Traveling Salesman Problem

time limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

problem descride

Nowadays British scientists has been investigating the opportunities to increase the performance of traditional computers. Recent research has shown that changing logical zero to logical right shift ( x = x / 2) and logical one to logical negation ( x = 1 - x) will lead to a significant architecture enhancement. Thus, new architecture will be able to solve some NP hard problems. Assume that mentioned above basic operations will be new zero and new one, respectively.

For example, well known traveling salesman problem solved in the proposed architecture will be equivalent to obtaining number (fraction) a2b\frac{a}{2^b}2ba? from a number of one (initial state). Therefore, you are required to write a program (sequence of zeros and ones) to solve traveling salesman problem for given a and b.

Input

Single line contains two integer numbers a and b.
1≤b≤601 ?≤?b?≤? 601??b??60,
1≤a<2b1 ?≤?a?<?2^b1??a?<?2b,
a is odd.

Output

Single line should contain a binary sequence, which is a solution for traveling salesman problem using new architecture. If there are multiple solutions, the minimal length program should be printed.

Sample Input

3 3

Sample Output

0010

題意描述

給定一個(gè)a和b,將初始值為1的數(shù)字,通過盡可能少的操作0(將數(shù)字變?yōu)樵瓉淼?span id="ozvdkddzhkzd" class="katex--inline">12\frac{1}{2}21?)和操作1(將數(shù)字變?yōu)?-原來的數(shù)字),變成值為a2b\frac{a}{2^b}2ba?

題目分析

一開始以為和目標(biāo)數(shù)字的二進(jìn)制有關(guān),但題目其實(shí)保證了目標(biāo)數(shù)字絕對(duì)能通過所給的兩個(gè)操作算出來,所以逆向思維。從目標(biāo)數(shù)字出發(fā),若當(dāng)前數(shù)字大于12\frac{1}{2}21?則說明當(dāng)前數(shù)字是由某個(gè)數(shù)字通過操作1之后得到的,因?yàn)榻?jīng)過操作1和操作0的數(shù)字必定小于1。如果通過操作0而得到一個(gè)大于12\frac{1}{2}21?的數(shù)字,那么原數(shù)字則大于1。這是顯然錯(cuò)誤的。若當(dāng)前數(shù)字小于12\frac{1}{2}21?,則說明當(dāng)前數(shù)字是通過操作0得到的。從而逆推出正確的操作順序。

具體代碼

#include <iostream> #include <algorithm> #include <vector> #include <map>using namespace std;const int maxn = 1e6 + 7;long long a, b, cnt; int ans[maxn];long long qpow(long long a, long long x) {long long res = 1;while (x){if(x&1) res *= a;a = a * a;x /= 2;}return res; }int main() {cnt = 0;cin >> a >> b;b = qpow(2, b);while(a != b){if (2 * a > b){a = b - a;ans[++cnt] = 1;}else{b /= 2;ans[++cnt] = 0;}}for (int i = cnt; i >= 1; i--) cout << ans[i];return 0; }

總結(jié)

以上是生活随笔為你收集整理的B-Traveling Salesman Problem[CF-Gym-102134][2016-2017 7th BSUIR Open Programming Contest]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。