【codechef】The Warehouse(灵活题)
来源:互联网 发布:如何进入淘宝vip商场 编辑:程序博客网 时间:2024/05/05 12:39
https://www.codechef.com/problems/WPROB/
做法挺巧妙的。首先枚举所有最后排序可能,对每种情况进行讨论:规定最后的顺序是o1o2o3。如果s[i]==o1,那么s[i]要移到最左边o1块里的最右边,移动的距离肯定是c2+c3,因为o1已经都在最左边,肯定要经过现有o2o3个数。o2类推。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define mod 1000000007using namespace std;string s;long long int ans;void fun(char o1,char o2,char o3){long long int tmp=0,c1=0,c2=0,c3=0;for(int i=0;i<s.length();i++){if(s[i]==o1){c1++;tmp+=c2+c3;}else if(s[i]==o2){c2++;tmp+=c3;}elsec3++;}ans=min(ans,tmp);}int main(){ std:ios_base::sync_with_stdio(false); int t; cin>>t; while(t--) { ans=100000000000LL; cin>>s; fun('b','g','r'); fun('b','r','g'); fun('g','b','r'); fun('g','r','b'); fun('r','b','g'); fun('r','g','b'); cout<<ans<<"\n"; } return 0;}
0 0
- 【codechef】The Warehouse(灵活题)
- 【codechef】Gcd Queries(灵活题,分类)
- 【codechef】 Zeroes(大数灵活题)
- 【codechef】Arush Challenge(灵活题)
- 【codechef】Strings Classes(枚举灵活题)
- 【codechef】Set Difference (灵活题,超时)
- 【codechef】Chef and Strange Formula(找规律,灵活题)
- 【codechef】Chef and Polygons(灵活题,坑题)
- 【codechef】括号匹配,求子串最大值(灵活题)
- Building the Data Warehouse
- POJ-2946-The Warehouse
- SQL Exercises/The warehouse
- CodeChef Protecting The Poison(贪心)
- The Microsoft Data Warehouse Toolkit
- codechef The Army
- Codechef Reach The Point
- (codechef)The Next Palindrome
- CODECHEF Fill The Matrix
- LeetCode Problem:Two Sum
- Shiny应用基础(6):数据响应的触发与阻止
- 2014-2015 ACM-ICPC, Asia Xian Regional Contest C – The Problem Needs 3D Arrays(最大密度子图)
- Git学习第一天:安装Git并创建第一个仓库
- J2SE—线程基础知识积累
- 【codechef】The Warehouse(灵活题)
- wireshark使用教程(之1)
- NDK开发之ndk-build命令详解
- PHP和Nginx的交互方式
- C++入门经典 笔记 (第十一章)开发高级指针
- Hexo博客网站再配置
- UVALive 5103 / HDU 3695 Computer Virus on Planet Pandora(AC自动机裸)
- Next Permutation
- 排序与查找