SRM470
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的更多相关文章
- SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)
SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...
- Topcoder 好题推荐
SRM SRM147 DIV1 1000pt DP SRM148 DIV1 1100pt 递归 SRM149 DIV1 1000pt math SRM150 DIV1 500pt DP SRM469 ...
随机推荐
- (O)JS高阶函数应用——函数节流
在一些函数需被频繁调用的场景,如:window.onresize.mousemove.scroll滚动事件.上传进度等等,操作频繁导致性能消耗过高,而造成浏览器卡顿现象,我们可以通过函数节流的方式解决 ...
- 如何为linux系统设置全局的默认网络代理
方法1:更改全局配置文件/etc/profile all_proxy="all_proxy=socks://proxy.xxx.com.cn:80/" ftp_proxy=&quo ...
- Codeforces 782C. Andryusha and Colored Balloons 搜索
C. Andryusha and Colored Balloons time limit per test:2 seconds memory limit per test:256 megabytes ...
- mysql错误日志
cat /etc/my.cnf
- Eigen中的map
Map类用于通过C++中普通的连续指针或者数组 (raw C/C++ arrays)来构造Eigen里的Matrix类,这就好比Eigen里的Matrix类的数据和raw C++array 共享了一片 ...
- 《Django By Example》第一章 学习笔记
首先看了下目录,在这章里 将会学到 安装Django并创建你的第一个项目 设计模型(models)并且生成模型(model)数据库迁移 给你的模型(models)创建一个管理站点 使用查询集(Quer ...
- kbmMW均衡负载与容灾(3)(转载红鱼儿)
在kbmMW均衡负载与容灾(1)中,介绍了利用ClientTransport的OnReconnect事件,对联接的应用服务器的地址进行更换,做容灾处理.实际上,作者还给我们提供了另外一种机制,直接在C ...
- Linux 第三天
2.文件处理命令 1)touch 创建空文件 语法:touch文件名 2)cat 显示文件内容 英文原意:concatenate 语法:cat 文件名 常用选项: -n:number,显示行号 3)t ...
- 牛客训练三:处女座和小姐姐(三)(数位dp)
题目链接:传送门 思路:数位dp的记忆化搜索模板 从高位向低位枚举,逐位确定每一位的6的个数,dp[i][s]表示处理到第i条边,状态为s时的数字的个数. 注意,要使用long long类型. #in ...
- RabbitMQ c#版实现(转)
出处:https://www.cnblogs.com/hanfan/p/9842301.html 网上很多人已经总结的很好了,比如今天看到的这个.https://www.cnblogs.com/Lip ...