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. Squid 搭建正向代理服务器

    Squid 是一款缓存代理服务器软件,广泛用于网站的负载均衡架构中,常见的缓存服务器还有varnish.ATS等. 正向代理服务器可满足内网仅有一台服务器可以上网,而要供内网所有机器上网的需求,也可以 ...

  2. Qt样式表的使用

    Qt中可以灵活的使用层叠样式表(CSS),其语法和CSS很相似.因为HTML CSS的灵活性,所以可以很方便的为QT界面设计自己需要的外观.除了子类化Style类,使用QT样式表(QStyleShee ...

  3. Vim 基本配置

    1.关闭vi的一致性模式 set nocompatible 2.配置backspace的工作方式 set backspace=indent,eol,start 3.显示行号 set number 4. ...

  4. c# 反编译后窗口控件在vs中打不开的修改方法

    DialogResult.Cancel System.Windows.Forms.DialogResult.Cancel DialogResult.OK System.Windows.Forms.Di ...

  5. easyui 获取特定页签tab

    var findTab=$('#mytabs').tabs('getTab','财务信息').panel('options').tab; var findTabIndex = $('#tab').ta ...

  6. Vue 汇总

    1.右键菜单(防止默认行为) @contextmenu.native.prevent="rightClick()"

  7. IOS初级:UITableView

    先来看一下tableview 的结构(plain style). --------------------------------------       + header               ...

  8. Docker 介绍和使用

    Docker 技术可以实现容器装载软件和依赖库,类似于封闭的Linux系统,默认相当于有root权限,可以快速移植和部署到其他机器上. Docker 容器技术可以理解为:仓库(储物间),镜像(类似于面 ...

  9. python学习 day4 (3月5日)---列表

    列表: 容器性数据 有序  可更改 大量数据 一.增 1.追加    append(objcet) 2.索引增加   Insert(index,元素) 3.迭代追加   extend(object) ...

  10. 【转】如何用Redis做LRU-Cache

    LRU(Least Recently Used)最近最少使用算法是众多置换算法中的一种. Redis中有一个maxmemory概念,主要是为了将使用的内存限定在一个固定的大小.Redis用到的LRU ...