250pt

给定1个最多16颜色的字符串(颜色可以重复),甲在最左边,乙在最右边。轮流操作,每次可以消除一种颜色。

给定一个k,问谁能最先消除完到位置k之间的障碍。

思路:

每个人肯定优先取对方没有的,,所以直接模拟即可

 #line 7 "DoorsGame.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair
#define two(i) (1 << i)
#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class DoorsGame
{
public:
int determineOutcome(string s, int p)
{
int n = s.size(), S = , S1 = ;
for (int i = ; i < p; ++i)
S |= ( << (s[i] - 'A'));
for (int i = p; i < n; ++i)
S1 |= ( << (s[i] - 'A'));
int same = S & S1;
int ans = , j;
while (){
j = -;
for (int i = ; i < ; ++i)
if (S & two(i)){
if (j == - || !(two(i) & same)) j = i;
}
S -= two(j);
if (S1 & two(j)) S1 -= two(j);
++ans;
if (S == ){
if (S1 == ) return ;
return ans;
} j = -;
for (int i = ; i < ; ++i)
if (S1 & two(i)){
if (j == - || !(two(i) & same)) j = i;
}
S1 -= two(j);
if (S & two(j)) S -= two(j);
++ans;
if (S1 == ){
if (S == ) return ;
return -ans;
}
}
return ;
}
};

500pt

两排点,每排n个.上排的和下排的连线.事先已经有些线连好了.求考虑所有的连线方案时,连线交点个数的期望

思路:
        三类计数:事先已经连好的线间的交点数.新增连线和原有连线的交点数期望.新增连线之间交点期望.

 // BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "DrawingLines.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class DrawingLines
{
public:
double countLineCrossings(int n, vector <int> s, vector <int> t)
{
int m = s.size();
double ret = (n - m) * (n - m - 1.0) / 4.0;
for (int i = ; i < m; ++i)
for (int j = i + ; j < m; ++j)
if ((s[i] < s[j] && t[i] > t[j]) || (s[i] > s[j] && t[i] < t[j])) ret += 1.0;
for (int i = ; i < m; ++i){
double s1 = s[i] - , s2 = n - s[i], t1 = t[i] - , t2 = n - t[i];
for (int j = ; j < m; ++j){
if (s[j] < s[i]) --s1;
if (s[j] > s[i]) --s2;
if (t[j] < t[i]) --t1;
if (t[j] > t[i]) --t2;
}
ret += (s1 * t2 + s2 * t1) / (t1 + t2);
}
return ret;
} };

SRM470的更多相关文章

  1. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  2. Topcoder 好题推荐

    SRM SRM147 DIV1 1000pt DP SRM148 DIV1 1100pt 递归 SRM149 DIV1 1000pt math SRM150 DIV1 500pt DP SRM469 ...

随机推荐

  1. hdu 5692(dfs+线段树) Snacks

    题目http://acm.hdu.edu.cn/showproblem.php?pid=5692 题目说每个点至多经过一次,那么就是只能一条路线走到底的意思,看到这题的格式, 多个询问多个更新, 自然 ...

  2. lazarus,synedit输入小键盘特殊符号的补丁

    unit synedittextdoublewidthchars2; // fix up chinese symbel width //by steven {$mode objfpc}{$H+} in ...

  3. String、StringBuffer、StringBuilder和StringTokenizer的区别

    1)String.StringBuffer.StringBuilder都用于字符串操作,其中,String是不可变类,即String对象一旦被创建,其值不能被修改,而StringBuffer和Stri ...

  4. Getting svn to ignore files and directories

    August 27, 2013Software Developmentresources, subversion, svn, tutorial, version control Who knew it ...

  5. Spring访问数据库(方式上跟HQL类似,每行记录映射一个实体类)

    看了这篇技术博客,觉得收获较大,收藏了:http://sarin.iteye.com/blog/875915

  6. abp项目中无法使用HttpContext.Current.Session[""]的问题

    web项目Global.asax.cs中加入如下代码 public override void Init() { this.PostAuthenticateRequest += (sender, e) ...

  7. asio的网络通讯代码练手

    asio的网络基本模板(单例模式 消息队列 ) // MyAsio.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" #include < ...

  8. Subarray Sum Equals K LT560

    Given an array of integers and an integer k, you need to find the total number of continuous subarra ...

  9. Java SE EE ME用处

    Java SE: 又称J2SE,开发部署桌面应用程序: Java EE:又称J2EE,开发网站 Java ME:是做手机APP开发 EE在SE基础上构建,提供web服务.组件模型.管理和通信API

  10. Redis (非关系型数据库) 数据类型 之 list列表类型

    Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素到列表的头部(左边)或者尾部(右边) list即可以作为“栈”也可以作为"队列". 操作: >lpush ...