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. python入门:in 的用法(它在不在这个字符串里面)

    #!/usr/bin/env python # -*- coding:utf-8 -*- #in 的用法(它在不在这个字符串里面) #ret(返回,译音:ruai特) #给s赋值为字符串“Alex S ...

  2. thinkcmf常用标签

    1.图片地址:{:cmf_get_image_url($vo.icon)} 2.模板控件 模板变量调用:$theme_vars.title <widget name="aboutUs& ...

  3. eclipse使用技巧的网站收集——转载(二)

    写代码离不开文本编辑器,看代码也离不开,iar和keil编辑和阅读简直一般般了,因此使用eclipse可以看看代码,提高效率.网上有几个博客的文章,这里收集一下,以备忘. 以下文章转载自:http:/ ...

  4. 原来针对新唐mcu,keil有免费许可

    MDK for Nuvoton Cortex-M0/M23:The MDK for Nuvoton Cortex-M0/M23 is a license paid by Nuvoton. It is  ...

  5. python——全局变量&局部变量

    >>> count = 5 >>> def function(): count = 10 print(10) >>> function() 10 ...

  6. poj 3280 回文字符串问题 dp算法

    题意:给一个字符串,构成回文(空也是回文) 其中增删都需要代价.问:代价最少? 思路:把字符串s变空  dp[i][j]表示变成回文的最小代价 for(i=m-1;i>=0;--i)       ...

  7. poj 2376 选择工作区间问题 贪心算法

    题意:给一些工作区间,如何选取最小的工作数量,覆盖[1,T]的工作时长 一开始的思路,当然也是错误的思路: 我想着,最小工作数量是吧?那肯定就是选择结束时间最晚的,给结束时间来一个排序.哎这个思路错误 ...

  8. 给vagrant中的precise64升级VBoxGuestAdditions

    位置:/usr/share/virtualbox/VBoxGuestAdditions.iso 在host(ubuntu 12.04 64)中: 查看虚拟机的名字:jb@H38:~/vm/vagran ...

  9. luogu4016 负载平衡问题

    网络流不用动脑子的好爽啊 #include <iostream> #include <cstring> #include <cstdio> #include < ...

  10. luogu3386 【模板】二分图匹配 匈牙利算法 hdu2063 过山车 dinic

    luogu 匈牙利算法 #include <iostream> #include <cstring> #include <cstdio> using namespa ...