Codeforces Gym101606 D.Deranging Hat (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))
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))的更多相关文章
- Codeforces Gym101606 A.Alien Sunset (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))
2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017) 寒假第一次组队训练赛,和学长一起训练,题目难度是3颗星,我和猪队友写 ...
- [寒假集训第一场]gym101606 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)
3星场 难度在于英文题面太难读懂了QAQ 看样例猜题意的我 博客园的c++主题真丑 A Alien Sunset \(description\) 有\(n\)个星球,每个星球自转时间不一样,所以一天的 ...
- 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){ ...
- 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< ...
- 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< ...
- 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< ...
- Codeforces Gym101606 E.Education (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))
E Education 这个题有点意思,就是找满足条件的最小价格里的最大值的人数,有点贪心的思想吧,一开始写错了,人群的那个不能排序,而且是最小价格里找能住下人最多的部门,让这个部门去住这个房间.在循 ...
- 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/ ...
- 2017 United Kingdom and Ireland Programming(Gym - 101606)
题目很水.睡过了迟到了一个小时,到达战场一看,俩队友AC五个了.. 就只贴我补的几个吧. B - Breaking Biscuits Gym - 101606B 旋转卡壳模板题.然后敲错了. 代码是另 ...
随机推荐
- H5bulider中的微信支付配置注意事项
一.云打包安卓自定义证书的生成: 签名算法名称: SHA1withRSA主体公共密钥算法:1024 位 RSA 密钥密钥库类型:JKS 1.下载JDK1.6安装,切换到bin目录,打开命令行: 2.生 ...
- 《linux设备驱动开发详解》笔记——7并发控制
linux中并发无处不在,底层驱动需要考虑. 7.1 并发与竞争 7.1.1 概念 并发:Concurrency,多个执行单元同时.并行执行 竞争:Race Condistions,并发的执行单元对共 ...
- Python基础——字典(dict)
由键-值对构建的集合. 创建 dic1={} type(dic1) dic2=dict() type(dic2) 初始化 dic2={'hello':123,'world':456,'python': ...
- django知识分支_1
django知识分支 1.Cookie工作流程: 浏览器向服务器发出请求,服务器接收到浏览器的请求进行处理,服务器设置一个cookie发送给浏览器,浏览器将cookie保存,当需要再次登录的时候,浏览 ...
- day24 01 初识继承
day24 01 初识继承 面向对象的三大特性:继承,多态,封装 一.继承的概念 继承:是一种创建新类的方式,新建的类可以继承一个或者多个父类,父类又可称基类或超类,新建的类称为派生类或者子类 cla ...
- python的标准模块
本文用于记录python中的标准模块,随时更新. decimal模块(解决小数循环问题): >>> import decimal >>> a = decimal.D ...
- leetcode-22-string
521. Longest Uncommon Subsequence I find the longest uncommon subsequence of this group of two strin ...
- Windows7_64位 NVIDIA 卡 OpenCl环境配置
序 最近做一个项目需要用到OpenCL,由于之前没有接触过,所以在环境配置第一关就遇到了一些问题,查阅很多资料才配置完成,现在记录如下,希望给一些童鞋一些帮助. 整个步骤也很简单: 了解系统配置,选择 ...
- poj 2229 拆数问题 dp算法
题意:一个n可以拆成 2的幂的和有多少种 思路:先看实例 1 1 2 1+1 2 3 1+1+1 1+2 4 1+1+1+1 1+1+2 2+2 4 5 ...
- bash之条件测试if/else
bash之条件测试: if/then结构 条件测试(CONDITION): test EXPRESSION:测试条件表达式正确否 [ EXPRE ...