D Deranging Hat

这个题简直了,本来想的是冒泡排序然后逆着输出来的,后来发现不对,因为题目上求的是最优解,而且冒泡的话,输出结果有的超出10000行了,所以就是把一开始的,排好序的字母标记一下位置,然后再把要求的串的位置记录一下,从大到小输出来,鬼知道这道题到底要干嘛,反正有人写出来了而且他自己都解释不清楚他为什么这么写。。。

代码:(不是我的)

 1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cstdio>
5 #include<math.h>
6 #include<cstdlib>
7 #include<set>
8 #include<map>
9 #include<stack>
10 #include<queue>
11 #include<vector>
12 #include<set>
13 #define ll long long int
14 #define INF 0x3f3f3f3f
15 #define mod 1000000007
16 #define me(a,b) memset(a,b,sizeof(a))
17 using namespace std;
18 struct node{
19 char str;
20 int pi;
21 }s[1005];
22 char str[1005];
23 int a[10005],b[10005],c;
24 bool cmp(node a,node b){
25 if(a.str!=b.str) return a.str<b.str;
26 return a.pi<b.pi;
27 }
28 int main(){
29 scanf("%s",&str);
30 int l=strlen(str);
31 for(int i=0;i<l;i++){
32 s[i].str=str[i];
33 s[i].pi=i;
34 }
35 sort(s,s+l,cmp);
36 c=0;
37 int n[1005];
38 for(int i=0;i<l;i++){
39 n[s[i].pi]=i;
40 }
41 for(int i=0;i<l;i++){
42 if(s[i].pi!=i){
43 a[c]=i;
44 b[c]=s[i].pi;
45 c++;
46 int pre=s[i].pi;
47 int now=n[i];
48 swap(s[now],s[i]);
49 n[pre]=now;
50 }
51 }
52 for(int i=c-1;i>=0;i--){
53 printf("%d %d\n",b[i]+1,a[i]+1);
54 }
55 return 0;
56 }

Codeforces Gym101606 D.Deranging Hat (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))的更多相关文章

  1. Codeforces Gym101606 A.Alien Sunset (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017) 寒假第一次组队训练赛,和学长一起训练,题目难度是3颗星,我和猪队友写 ...

  2. [寒假集训第一场]gym101606 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)

    3星场 难度在于英文题面太难读懂了QAQ 看样例猜题意的我 博客园的c++主题真丑 A Alien Sunset \(description\) 有\(n\)个星球,每个星球自转时间不一样,所以一天的 ...

  3. 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)

    A. Alien Sunset 暴力枚举答案即可. #include<cstdio> int n,i,mx; struct P{ int h,r,t; bool night(int x){ ...

  4. Codeforces Gym101606 C.Cued In (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    C Cued In 这个题是打球的.都忘了写的什么了... 代码: 1 #include<iostream> 2 #include<cstring> 3 #include< ...

  5. Codeforces Gym101606 J.Just A Minim (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    J Just A Minim 超级无敌大水题,但是被精度卡了一手,输出要精确到小数点后6位,我直接输出的... 代码: 1 #include<iostream> 2 #include< ...

  6. Codeforces Gym101606 I.I Work All Day (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    I I Work All Day 这个题就是取模找最小的. 代码: 1 #include<iostream> 2 #include<cstdio> 3 #include< ...

  7. Codeforces Gym101606 E.Education (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    E Education 这个题有点意思,就是找满足条件的最小价格里的最大值的人数,有点贪心的思想吧,一开始写错了,人群的那个不能排序,而且是最小价格里找能住下人最多的部门,让这个部门去住这个房间.在循 ...

  8. 2019.04.11 第四次训练 【 2017 United Kingdom and Ireland Programming Contest】

    题目链接:  https://codeforces.com/gym/101606 A: ✅ B: C: ✅ D: ✅ https://blog.csdn.net/Cassie_zkq/article/ ...

  9. 2017 United Kingdom and Ireland Programming(Gym - 101606)

    题目很水.睡过了迟到了一个小时,到达战场一看,俩队友AC五个了.. 就只贴我补的几个吧. B - Breaking Biscuits Gym - 101606B 旋转卡壳模板题.然后敲错了. 代码是另 ...

随机推荐

  1. destoon 后台入口文件分析

    <?php/* [Destoon B2B System] Copyright (c) 2008-2015 www.destoon.com This is NOT a freeware, use ...

  2. 【markdown】 markdown 语法

    介绍几个 markdown 语法学习地址和相关工具 参考链接 coding gitlab markdown offical markdown editor markdown editor2

  3. 第一课 项目的介绍 Thinkphp5第四季

    学习地址: https://study.163.com/course/courseLearn.htm?courseId=1004887012#/learn/video?lessonId=1050543 ...

  4. HDU 5025 Saving Tang Monk(状态转移, 广搜)

    #include<bits/stdc++.h> using namespace std; ; ; char G[maxN][maxN], snake[maxN][maxN]; ]; int ...

  5. UVALive - 8273 Assigning Frequencies (搜索 )

    n个点的一张图,问能否给每个点染上三种颜色中的一种,使得没有相邻的点颜色相同? n <= 35. Sample Input 4 6 6 0 3 1 5 3 2 2 5 0 4 1 0 7 12 ...

  6. 蓝桥--2n皇后问题(递归)--搬运+整理+注释

    N皇后问题: #include <iostream> #include <cmath> using namespace std; int N; ];//用来存放算好的皇后位置. ...

  7. 20188472 https://www.cnblogs.com/chenzg90826/

    我是一名学计算机的大一学生,对学计算机比较感兴趣,但是对于计算机的了解程度还不够深,所以我在这方面还只是一个初学者.经过了一个学期对计算机和编程语言的学习,我觉得要真正的学好这门专业真的还要更努力.在 ...

  8. 配置hibernate常见问题

    连接MySql时出现:The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time z ...

  9. python补漏----isinstance 和 issubclass

    一.isinstance Python 中的isinstance函数 isinstance是Python中的一个内建函数 语法: isinstance(object, classinfo) 如果参数o ...

  10. Multi-Dimensional Recurrent Neural Networks

    Multi-Dimensional Recurrent Neural Networks The basic idea of MDRNNs is to replace the single recurr ...