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. iOS.Crash.OniOS8.WhenCall[popToRootViewController]

    系统iOS 8.x, ARC. CrashCase: 在UIViewController中有一个类型为UIScrollView的实例变量scrollView, 点击UIViewController中的 ...

  2. linux下gcc默认搜索的头文件及库文件路径

    转自:https://blog.csdn.net/fd315063004/article/details/7925854 一.头文件 gcc 在编译时如何去寻找所需要的头文件:※所以header fi ...

  3. BZOJ1047或洛谷2216 [HAOI2007]理想的正方形

    BZOJ原题链接 洛谷原题链接 显然可以用数据结构或\(ST\)表或单调队列来维护最值. 这里采用单调队列来维护. 先用单调队列维护每一行的最大值和最小值,区间长为正方形长度. 再用单调队列维护之前维 ...

  4. Java中关键字static的使用

    static 关键字 1).static只能修饰成员变量或成员方法,所有非静态是对象相关的,所有静态是类相关的. 2)被static修饰的成员变量成员方法独立于该类的任何对象,它不依赖类的特定的实例, ...

  5. C++连接MySQL(Windows)

    一般来说,VS下采用微软自身的SQL Server是比较常见的做法,但SQL Server只适合学习,不适合真正应用.在此,我们选择MySQL作为后台数据库.C++语言本身并没有提供访问数据库的东西, ...

  6. 强大的easygrid V7 ,可联系作者

    增加历史记录事件 修改bug 修改风格 演示绑定表达式 下载demo

  7. 八大排序算法的Java代码实现

    简单插入排序 public class QuickSort { private static void quickSort(int [] a, int low, int high){ if (low ...

  8. vue动态路由配置,vue路由传参

    动态路由: 当我们很多个页面或者组件都要被很多次重复利用的时候,我们的路由都指向同一个组件,这时候从不同组件进入一个"共用"的组件,并且还要传参数,渲染不同的数据 这就要用到动态路 ...

  9. 基于注解的接口限流+统一session认证

    代码心得: 一个基本的做法:对于用户身份认证做到拦截器里,针对HandlerMethod进行统一拦截认证,根据方法上的注解标识,判别是否需要身份验证,并将查找出来的User实体存入ThreadLoca ...

  10. Windows8 App Store 开发者会关心的文档

    在远程计算机上从 Visual Studio 调试和测试 Windows 应用商店应用程序 http://msdn.microsoft.com/zh-cn/library/windows/apps/h ...