顺利搞出  A B 两题,然后压线晋级了,手速场。

A 题 , 求排列最小的,肯定从后往前来做,维护一个最小的set,只是第一个字母要特判一下。

   1:  #line 5 "EllysSortingTrimmer.cpp"
   2:  #include <vector>
   3:  #include <list>
   4:  #include <map>
   5:  #include <set>
   6:  #include <deque>
   7:  #include <stack>
   8:  #include <bitset>
   9:  #include <algorithm>
  10:  #include <functional>
  11:  #include <numeric>
  12:  #include <utility>
  13:  #include <sstream>
  14:  #include <iostream>
  15:  #include <iomanip>
  16:  #include <cstdio>
  17:  #include <cmath>
  18:  #include <cstdlib>
  19:  #include <ctime>
  20:  #include <cstring>
  21:  using namespace std;
  22:  int i,j,k;
  23:  #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
  24:  #define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
  25:   
  26:   
  27:  class EllysSortingTrimmer
  28:  {
  29:  public:
  30:  string getMin(string S, int L)
  31:  {
  32:      vector<char> s;
  33:      for(int i=1; i<S.size(); i++) s.push_back(S[i]);
  34:      sort(s.begin(),s.end());
  35:      vector<char> t;
  36:      for(int i=0; i<L-1; i++) t.push_back(s[i]);
  37:      t.push_back(S[0]);
  38:      sort(t.begin(), t.end());
  39:      string ret;
  40:      for(int i=0; i<L; i++) ret += t[i];
  41:      return ret;
  42:  }
  43:   
  44:   
  45:  };
  46:   

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

B题  不要搞成匹配的问题,每一个字母都有一个位置范围,所以只要维护一个set,保证其能够被写入,其余时间都插入最小就OK

   1:  #line 5 "EllysScrabble.cpp"
   2:  #include <vector>
   3:  #include <list>
   4:  #include <map>
   5:  #include <set>
   6:  #include <deque>
   7:  #include <stack>
   8:  #include <bitset>
   9:  #include <algorithm>
  10:  #include <functional>
  11:  #include <numeric>
  12:  #include <utility>
  13:  #include <sstream>
  14:  #include <iostream>
  15:  #include <iomanip>
  16:  #include <cstdio>
  17:  #include <cmath>
  18:  #include <cstdlib>
  19:  #include <ctime>
  20:  #include <cstring>
  21:  using namespace std;
  22:  int i,j,k;
  23:  #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
  24:  #define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
  25:   
  26:   
  27:  class EllysScrabble
  28:  {
  29:  public:
  30:  string getMin(string letters, int maxDistance)
  31:  {
  32:      pair<char, int> X;
  33:      vector<pair<char, int> > S;
  34:      for(int i=0; i<letters.size(); i++)
  35:      {
  36:          S.push_back( make_pair(letters[i], i));
  37:      }
  38:   
  39:      string ret;
  40:   
  41:      vector<pair<char, int> > tmp;
  42:      for(int i=0; i<  min(letters.size() *1.0,maxDistance + 1.0); i++) tmp.push_back(make_pair(letters[i], i));
  43:      for(int i=0; i<letters.size(); i++)
  44:      {
  45:          // search
  46:          sort(tmp.begin(), tmp.end());
  47:          bool flag = 0;
  48:          for(int j=0; j< tmp.size(); j++)
  49:          {
  50:              if(i - tmp[j].second == maxDistance)
  51:              {
  52:                  ret += tmp[j].first;
  53:                  tmp.erase(tmp.begin() + j);
  54:                  flag = true;
  55:                  break;
  56:              }
  57:          }
  58:          if(flag == false)
  59:          {
  60:              ret += tmp[0].first;
  61:              tmp.erase(tmp.begin());
  62:          }
  63:   
  64:          // push
  65:          if(i + maxDistance + 1 < letters.size())
  66:          {
  67:              tmp.push_back(S[ i+ maxDistance +1]);
  68:          }
  69:      }
  70:      return ret;
  71:  }
  72:   
  73:   
  74:  };
  75:   

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

C题   这个题目开始的时候没搞出来,其实当时已经发下了 YYY, NY YN3种情况肯定会有一个是亮的。但是没有仔细想。这个为什么贪心是对的呢?给出每一个序列,NY YN YYY一定是最大的,这个仔细推了一下好像是对的!但是有没有严格证明出来。

#line 5 "EllysLamps.cpp"
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int i,j,k;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) class EllysLamps
{
public:
int getMin(string lamps)
{
int num = 0; for(int i=0; i<lamps.size();)
{
if(i+1 < lamps.size() && lamps[i] != lamps[i+1])
{
i+=2;
num++;
}else if(i+2 < lamps.size() && lamps[i] == lamps[i+1] && lamps[i] == lamps[i+2] && lamps[i]== 'Y')
{
i+=3;
num++;
}else i++;
}
return num;
} };

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

TCO 2014 Round 1A的更多相关文章

  1. TCO 2014 Round 1C 概率DP

    TCO round 1C的 250 和500 的题目都太脑残了,不说了. TCO round 1C 950 一个棋子,每次等概率的向左向右移动,然后走n步之后,期望cover的区域大小?求cover, ...

  2. 模拟 Coder-Strike 2014 - Round 1 A. Poster

    题目地址:http://codeforces.com/problemset/problem/412/A /* 模拟:题目没看懂,但操作很简单,从最近的一头(如果不在一端要先移动到一端)往另一头移动,顺 ...

  3. Coder-Strike 2014 - Round 2

    t题目链接:Coder-Strike 2014 - Round 2 A题:简单水题,注意能加入反复的数字.因此仅仅要推断是否能把Min和Max加入好.就能够了 B题:开一个sum计算每一个聊天总和,和 ...

  4. [Google Codejam] Round 1A 2016 - The Last Word

    [Problem Description] Problem On the game show The Last Word, the host begins a round by showing the ...

  5. Google Code Jam Round 1A 2015 解题报告

    题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间 ...

  6. 2005 TCO Online Round 1 - RectangleError

    RectangleError Problem's Link Problem Statement You want to draw a rectangle on a piece of paper. Un ...

  7. Coder-Strike 2014 - Round 1 D. Giving Awards

    题目的意思是 老板给n个人发工资,x欠y的工资,the joy of person x from his brand new money reward will be much less, 老板想避免 ...

  8. Coder-Strike 2014 - Round 1 E. E-mail Addresses

    此题题意就是匹配邮箱,提交时一直在test 14上WA,看了测试用例之后才发现计数用的int溢出,要用long long还是做题经验不够,导致此题未能通过,以后一定要考虑数据量大小 题意是找出邮件地址 ...

  9. Coder-Strike 2014 - Round 1 C. Pattern

    题目的意思是给出n个长度相同的字符串然后找出与他们匹配的字符串 将字符串存入类似二维数组的里面,每一行代表一个字符串,遍历每列,判断每列是否有公共的匹配字符,如果有输出任意一个 如果没有输出'?' # ...

随机推荐

  1. 根据字符串计算UILabel尺寸

    iOS开发中经常会遇到UILabel大小尺寸不固定的情况,需要根据文字内容变化,这时候就需要计算文字大小以自动改变UILabel的尺寸. iOS7之后计算尺寸只需要一个方法就可以: - (CGSize ...

  2. JAVA白盒安全测试需要关注的API

    JAVA白盒安全测试需要关注的APIhttp://blog.csdn.net/testing_is_believing/article/details/19502167

  3. CSS Selector (part 1)

    Selector概述 示例: strong { color: red; } 解释: 这是一个完整 css 规则(标签选择器).strong 叫做选择器,它选择该规则将被应用到 DOM 的那个元素上去. ...

  4. CentOS 6.x安装gcc 4.8/4.9/5.2

    1.gcc 4.8 cd /etc/yum.repos.d wget http://people.centos.org/tru/devtools-2/devtools-2.repo -gcc -bin ...

  5. 使用VERT.X构建分布式企业级应用

    谈到企业应用,就得谈分布式.低耦合.模块化.面向服务.可扩展性等等.早些时候的技术有CORBA和EJB,后面兴起的有WebService和MDB.但是这些技术不是学习.开发门槛高就是不那么轻量化.我现 ...

  6. Object-C中的内存管理小记

    //错解1:内存泄露 - (void)setObj:(Object *)newObj { obj = [newObj retain]; } 当新旧对象指向不同时,执行这段代码后,obj会指向另一个对象 ...

  7. 第三篇、FMDB使用

    简介: FMDB是基于SQlite3的封装一个第三方的OC库,操作起来更加简单,性能比Coredata更加高. 1.创建sqlite文件 2.导入FMDB头文件 3.创建数据库表table 4.编写s ...

  8. iOS App Transport Security

    网络请求提示:Application Transport Security has blocked a cleartext HTTP (http://) resource load since it ...

  9. 懒人记录 Hadoop2.7.1 集群搭建过程

    懒人记录 Hadoop2.7.1 集群搭建过程 2016-07-02 13:15:45 总结 除了配置hosts ,和免密码互连之外,先在一台机器上装好所有东西 配置好之后,拷贝虚拟机,配置hosts ...

  10. java培训(5-8节课)

    面向对象: 1.利用面向对象的语法,实现代码的拆分(数据存储:对象的传值). 2.利用面向对象的语法,实现程序的结构处理(继承,多态,接口,抽象类). 3.用面向对象的编程方法,理解实现程序开发的框架 ...