1. 程式人生 > >2014ICPC World final A題(未解之謎)

2014ICPC World final A題(未解之謎)

未解之謎,先mark一下。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
#include <ctime>
#define LL __int64
#define eps 1e-8
using namespace std;
int a[1000];
int n,i;
int main()
{
	while (~scanf("%d",&n))
	{
		memset(a,0,sizeof(a));
		for (i=1;i<=2*n;i++)
			if (i%2) a[i]=2;
				else a[i]=1;
		int begin=-1;
		int end=2*n-2;
		int gg=0,ff=0;
		int t=0;
		while (end>n && begin<n)
		{
			while (!(a[end]==1 && a[end+1]==2 && a[end+2]!=2) && end>n) end--;
			if (end<=n) 
			{gg=1;break;}
			printf("%d to %d\n",end,begin);
			t++;
			a[begin]=1;a[begin+1]=2;
			while (!(a[begin]==2 && a[begin-1]!=2 && a[begin+1]==1) && begin<n) begin++;
			if (begin>=n) {
				ff=1;break;}
			printf("%d to %d\n",begin,end);
			t++;
			a[end]=2;a[end+1]=1;
		}
		if (ff==1)
		{
			while (!(a[begin]==2 && a[begin-1]==2 && a[begin+1]==1)) begin--;
			printf("%d to %d\n",begin,end);
			t++;
			a[end]=2;a[end+1]=1;
		}
		if (gg==1)
		{
			while (!(a[end]==1 && a[end+1]==2 && a[end+2]==2)) end--;
			printf("%d to %d\n",end,begin);
			t++;
			a[begin]=1;a[begin+1]=2;
		}
		int k=-3;
		end=2*n-1;
		begin=0;
		while (end>n && begin<n)
		{
			while (!(a[end]==1 && a[end+1]==1)&&end>n) end--;
			if (end<=n) break;
			printf("%d to %d\n",end,k);
			t++;
			if (t>=n) break;
			k-=2;
			while (!(a[begin]==2 && a[begin+1]==2)&&begin<n) begin++;
			if (begin>=n) break;
			printf("%d to %d\n",begin,end);
			t++;
			if (t>=n) break;
			begin++;
			end--;
		}
	}
	return 0;
}


相關推薦

2014ICPC World final A()

未解之謎,先mark一下。 #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream

ACM-ICPC 2018 world final A Catch the Plane

題目連線:https://icpc.kattis.com/problems/catch Catch the Plane Your plane to the ICPC Finals departs in a short time, and the only way to get

acm-洛谷P1109學生分組

div style post stream pac names 不理解 namespace algorithm 把每一組的學生個數調度到一個給定區間範圍內; 看了一圈題解,大佬都對原因避而不答; #include <iostream> #include <

學習python過程中遇到的

1.re模組 re.match得出來的結果是一個什麼東西,為什麼可以對它進行呼叫分組 2.如果我想知道一個函式的功能應該如何尋找? def add_p(img): draw=ImageDraw.Draw(img)#操作照片前先為它建立一個物件 # img.show()#顯示要操作的

很多終於有答案了——2018年JVM生態系統報告出爐

在Java開發者中,一直存在著很多鄙視鏈。如: IntelliJ → Eclipse → NetBeans Unix → Linux → Mac OS→ Windows → DOS Emacs → Vim → Sublime → Word → Power Point 這諸多鄙視鏈中一直存在著很大的

技術文章 | spring boot專案中使用jpa的一個

 本文來源於阿里雲-雲棲社群,原文點選這裡。 公司最近主要的工作就是把之前的一個專案進行幾乎全面的重構,之所以說幾乎全面,是因為除開業務邏輯外全部換血: 框架由spring+struts2+mybatis改為spring boot+jpa資料庫由sybase+h2改

問題 。arraylist.clear()另一個arraylist跟著被清空。

arraylist.clear()另一個arraylist跟著被清空。 package com.example.myapplication; import android.app.Activity; import

我的1--RSA

逆向得到一段註冊程式的虛擬碼,請推算出註冊碼 { int RSA(int message,int e,int N) {...} bool checkSerial(char *szSerial) { bool bResult=f

深度丨AI界的七大:OpenAI丟出一組AI研究課題

今天,OpenAI在官方部落格上丟出了7個研究過程中發現的未解決問題。OpenAI希望這些問題能

執行緒的

簡介: 這是檢驗多執行緒可見性(volatile關鍵字)的時候發現的問題。請不要再迴圈中使用System.out.println();這種程式碼,因為他是被synchronized修飾的,所以沒法用來檢測。有沒有大神能解釋一下,下面這些案例是什麼鬼???請不要

新疆十大。。。

1900年3月28日,瑞典探險家斯文·赫定完成了羅布泊西部的探險開始返程。這時,他和他的維吾爾族嚮導阿爾迪克發現用於考察的一把鏟子遺留在了營地。阿爾迪克返回營地尋找時遇到了風暴,迷失了方向,但卻在迷途中意外地闖入了一座古城,他發現了許多文物和雕刻精美的木板、古代銅錢。斯文·赫定對阿的發現大喜過忘。1903年,

CSS --

legend order 上傳 isp bold mail sub 標題 feed @、css那些事兒 -- 第9章 反饋表單 自己編寫了CSS,可是紅框中的橫線比下面的要粗。對比作者的代碼,發現可能與上面標題h3的height和line-height有關,但是不知道具體是

LeetCode算法兩個數組的交集

for mage != 有助於 class 學習 ret arr hash 題目背景: 這個與我們高中時期學習的交集是一樣的,順便復習一下相關的數學知識有助於更好的理解。 交集的定義: 對於兩個集合A和B,定義A和B的交集為C,其中C={x|x屬於A且X屬於B},

Oracle(甲骨文)這個龐然大物至今

一個從資料庫開發起步的公司,在風雨中蹣跚了40年,沒錯,Oracle在2017年美國《財富》500強中排名81,在世界500強中排名280,營業收入37047百萬美元,利潤8901百萬美元。這樣一個龐然大物、不注重介面、缺乏創新性的軟體公司,不應該像雅虎一樣,在網際網路的浪

A拼音轉數字

scan util length 響應 color sans pop -c 一行 輸入是一個僅僅包括拼音的字符串,請輸出相應的數字序列。轉換關系例如以下: 描寫敘述: 拼音 yi er san si wu liu qi ba jiu 阿拉伯數字 1

A變態青蛙跳

.... 問題 public log post 第一次 擁有 ati popu 一僅僅青蛙一次能夠跳上1級臺階,也能夠跳上2級……它也能夠跳上n級。求該青蛙跳上一個

軟考網路管理員(包含2004-2018歷年真+課本教材講義+視訊教程)

軟考-網路管理員2004-2018歷年考試真題以及詳細答案(試題和答案分離的哦),同時含有最新課本教材、複習筆記、網路管理員視訊教程。持續更新後續年份的資料。請點贊!!請點贊!!!絕對全部貨真價實的資料!!! 全網最全,獨此一家,費心整理,希望各位同學順利通過考試!!! 網路管理員歷

軟考初級程式設計師(包含1990-2018歷年真+課本教材+模擬試卷+視訊教程)

軟考-初級程式設計師1990-2018歷年考試真題以及詳細答案(試題和答案分離的哦),同時含有課本教材、模擬試卷、程式設計師視訊教程、考試知識點。持續更新後續年份的資料。請點贊!!請點贊!!!絕對全部貨真價實的資料!!!! 全網最全,獨此一家,費心整理,希望各位同學順利通過考試!!!

軟考軟體設計師(包含05-18年真、高清教程、學習筆記)

費心整理出來的,希望對軟考的同學有幫助。包含: 1、二、三、四版設計師教程; 2、2005年到2018年曆年軟考設計師真題以及答案,包含上下午的哈; 3、軟體設計師學習筆記; 下載地址百度網盤 https://pan.baidu.com/s/1X6kla3Gx-Up9B-

hihoCoder二:A + B詳

using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace ConsoleApp3 { class Program1 { sta