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. leetcode-27-exercise_bit maniputation

    461. Hamming Distance 解题思路: 把两个数的每一位和1比较,如果结果不同说明这两位不同.要比较32次. int hammingDistance(int x, int y) { i ...

  2. (转)git常见错误

      error: src refspec master does not match any. 引起该错误的原因是,目录中没有文件,空目录是不能提交上去的 error: insufficient pe ...

  3. 转:跟我一起写Makefile (PDF重制版)

    原文地址:http://seisman.info/how-to-write-makefile.html 其它一些问题  不妨看一下:http://blog.csdn.net/huyansoft/art ...

  4. LeetCode(166) Fraction to Recurring Decimal

    题目 Given two integers representing the numerator and denominator of a fraction, return the fraction ...

  5. poj-2533 longest ordered subsequence(动态规划)

    Time limit2000 ms Memory limit65536 kB A numeric sequence of ai is ordered if a1 < a2 < ... &l ...

  6. Leetcode 559. N叉树的最大深度

    题目链接 https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/description/ 题目描述 给定一个N叉树,找到其最大深度. ...

  7. 关于.ascx

    .ascx用户控件  参考系列教程User controls in asp.net - Part 104 用户控件包含了html.代码和其他Web或者用户控件的组合,并在Web服务器上以自己的文件格式 ...

  8. Linux学习-systemctl 针对 service 类型的配置文件

    systemctl 配置文件相关目录简介 现在我们知道服务的管理是透过 systemd,而 systemd 的配置文件大部分放置于 /usr/lib/systemd/system/ 目录内. 该目录的 ...

  9. sqlserver常用知识点备忘录(持续更新)

    背景 一个项目的开发,离不开数据库的相关操作,表/视图设计,存储过程,触发器等等数据库对象的操作是非常频繁的.有时候,我们会查找系统中类似的代码,然后复制/粘贴进行再进行相应的修改.本文的目的在于归纳 ...

  10. C#通过http post方式调用需要证书的webservice

    前一段时间做花旗银行的项目,用到花旗的接口是websevice,由于很多原因直接在项目中引用webservice不成功,于是就用了http post方式请求,把请求信息(xml格式)组装之后发送到服务 ...