CF814B An express train to reveries

思路:

模拟,枚举。

实现:

 1 #include <iostream>
 2 using namespace std;
 3
 4 const int N = 1005;
 5
 6 int a[N], b[N], cnt[N], n, x, y;
 7
 8 int main()
 9 {
10     cin >> n;
11     for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
12     for (int i = 0; i < n; i++) cin >> b[i];
13     for (int i = 1; i <= n; i++)
14     {
15         if (cnt[i] == 2) x = i;
16         else if (cnt[i] == 0) y = i;
17     }
18     for (int i = 0; i < n; i++)
19     {
20         if (a[i] == x)
21         {
22             a[i] = y;
23             int bad = 0;
24             for (int j = 0; j < n; j++)
25                 if (b[j] != a[j]) bad++;
26             if (bad == 1)
27             {
28                 for (int j = 0; j < n; j++) cout << a[j] << " ";
29                 return 0;
30             }
31             a[i] = x;
32         }
33     }
34     return 0;
35 }
时间: 2024-07-31 22:27:50

CF814B An express train to reveries的相关文章

Codeforces Round #418 B--An express train to reveries

Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that nig

Codeforces - 814B - An express train to reveries - 构造

http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种情况构造出来暴力验证对不对就行了. #include<bits/stdc++.h> using namespace std; #define ll long long int n; int s[1005]; int us[1005]; int t[1005]; int ut[1005]; int

Codeforces Round #418 B

An express train to reveries 题意:给2长度为n的数列a b,a b中至少存在一个i使得ai!=bi,构造一个数列p,使得恰好存在一个i使得ai!=pi,且恰好存在一个j使得aj!=pj,且p里面的数为1-n且无重复,输出p,保证有解 思路:题目保证有解,可知,最多存在2个i使得ai!=bi,最少一个,如果只有一个,那么好办,令p=a,将pi换成1-n中没有出现的那个数就可以了,如果有存在2个不等的数,那么令p=a(除开两个ai!=bi的位置),找出未出现的2个数,将

codeforces round 418 div2 补题 CF 814 A-E

A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300],b[300],n,k; bool cmp(int a,int b) { return a>b; } int main() {//freopen("t.txt","r",stdin); scanf("%d%d",&n,&k); f

Codeforces Round #418 (Div. 2)

A - An abandoned sentiment from past 由于所有的数组B内所有的数都不同,因此当k > 1是就可以使该序列不递增 当k = 1是,带入B[0],判断序列A是否递增就可以啦 #include <bits/stdc++.h> using namespace std; const int MAXN = 100008; int a[MAXN], b[MAXN]; int main() { int n, k; scanf("%d%d", &am

Transportation poj1040

Ruratania is just entering capitalism and is establishing new enterprising activities in many fields in- cluding transport. The transportation company TransRuratania is starting a new express train from city A to city B with several stops in the stat

英语新闻常用词汇与短语

英语新闻常用词汇与短语 经济篇 accumulated deficit 累计赤字 active trade balance 贸易顺差 adverse trade balance 贸易逆差 aid 援助 allocation of funds 资金分配 allotment 拨款 allowance/grant/subsidy 补贴,补助金,津贴 amortization 摊销,摊还,分期偿付 annuity 年金 article 物品,商品 assigned 过户 autarchy 闭关自守 av

UVA - 301

 Transportation  Ruratania is just entering capitalism and is establishing new enterprising activities in many fields including transport. The transportation company TransRuratania is starting a new express train from city A to city B with several st

POJ 1040 Transportation

链接:http://poj.org/problem?id=1040 Transportation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4235 Accepted: 1725 Description Ruratania is just entering capitalism and is establishing new enterprising activities in many fields in- cludi