国庆 day 7 上午




思路:模拟,set记录一下。
#include<set>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
set<int>se;
int n,k,x,ans;
int main(){
freopen("del.in","r",stdin);
freopen("del.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d",&x);
if(se.find(x)!=se.end()) k--;
else{
se.insert(x);
ans++;
}
}
if(k<=) cout<<ans<<endl;
else cout<<ans-k<<endl;
}





思路:搜索
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std; int board[][], isKing[][];
int dir[][] = {{, }, {, -}, {-, }, {-, -}};
int best_deep;
vector<int> w;
vector<int> ways; void dfs(int step, int x, int y, int isKing)
{
w.push_back(x * + y);
if (step > best_deep)
{
best_deep = step;
ways.clear();
ways.push_back(w[]);
}
else if (step > && step == best_deep)
{
ways.push_back(w[]);
} int dis_limit = isKing ? : ; for (int d = ; d < ; d++)
{
bool pass = false;
int passx = , passy = ;
for (int dis = ; dis <= dis_limit; dis++)
{
int nxtX = x + dis * dir[d][];
int nxtY = y + dis * dir[d][];
if (!( <= nxtX && nxtX < && <= nxtY && nxtY < ))
break;
if (board[nxtX][nxtY] == || board[nxtX][nxtY] == )
break;
if (pass && board[nxtX][nxtY] == )
break;
if (board[nxtX][nxtY] == )
{
pass = true;
passx = nxtX;
passy = nxtY;
}
else
{
if (!pass)
continue;
board[passx][passy] = ;
dfs(step + , nxtX, nxtY, isKing);
board[passx][passy] = ;
}
}
}
w.pop_back();
} bool getAvailable()
{
ways.clear();
w.clear();
best_deep = ;
for (int curX = ; curX < ; curX++)
for (int curY = ; curY < ; curY++)
if (board[curX][curY] == )
dfs(, curX, curY, isKing[curX][curY]);
if (best_deep == )
{
for (int curX = ; curX < ; curX++)
for (int curY = ; curY < ; curY++)
if (board[curX][curY] == )
{
if (isKing[curX][curY])
{
for (int x = curX + , y = curY + ; <= x && x < && <= y && y < ; x++, y++)
if (!board[x][y])
ways.push_back(curX * + curY);
else
break;
for (int x = curX + , y = curY - ; <= x && x < && <= y && y < ; x++, y--)
if (!board[x][y])
ways.push_back(curX * + curY);
else
break;
for (int x = curX - , y = curY + ; <= x && x < && <= y && y < ; x--, y++)
if (!board[x][y])
ways.push_back(curX * + curY);
else
break;
for (int x = curX - , y = curY - ; <= x && x < && <= y && y < ; x--, y--)
if (!board[x][y])
ways.push_back(curX * + curY);
else
break;
}
else
{
if (curX - >= && curY - >= && !board[curX - ][curY - ])
ways.push_back(curX * + curY);
if (curX - >= && curY + < && !board[curX - ][curY + ])
ways.push_back(curX * + curY);
}
}
}
if (!ways.size())
return false;
return true;
} int main(){
freopen("chess.in", "r", stdin);
freopen("chess.out", "w", stdout);
memset(board, , sizeof(board));
memset(isKing, , sizeof(isKing));
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
{
char c;
scanf(" %c", &c);
board[i][j] = c - '';
}
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
{
char c;
scanf(" %c", &c);
isKing[i][j] = c - '';
}
getAvailable();
if (!ways.size())
printf("0\n");
else {
sort(ways.begin(), ways.end());
printf("%d\n", (int)ways.size());
for (int i = ; i < (int)ways.size(); i++)
printf("(%d,%d)\n", ways[i] / + , ways[i] % + );
}
}



思路:状压DP.
对后续决策有影响的是什么?
现在已经吃了哪些馅饼
令F[i][s]表示考虑前i次馅饼掉落事件,吃了s这个二进制状态表示的馅饼,期望的美味值
对于每一次掉馅饼,枚举掉下来的馅饼是谁
若s&a[j]==a[j](a[j]为前提馅饼集合) F[i][s] -> F[i+1][s|(1<<(j-1))] 注意要 /n
递推的顺序?
一个起始状态,多个目标状态,正推会导致无效状态
反着推
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,x,y;
int w[],f[];
double dp[][];
int main(){
freopen("bonus.in","r",stdin);
freopen("bonus.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=;i<n;i++){
scanf("%d",&w[i]);
while(scanf("%d",&x)&&x) f[i]|=<<x-;
}
for(int s=;s<(<<n);s++) dp[k][s]=;
for(int i=k-;i>=;i--)
for(int s=;s<(<<n);s++)
for(int j=;j<n;j++)
if((s&f[j])==f[j]) dp[i][s]+=1.0/n*max(dp[i+][s],dp[i+][s|(<<j)]+w[j]);
else dp[i][s]+=1.0/n*dp[i+][s];
printf("%.6f\n",dp[][]);
}
国庆 day 7 上午的更多相关文章
- 国庆 day 3 上午
a[问题描述] 你是能看到第一题的 friends 呢. ——hja 怎么快速记单词呢?也许把单词分类再记单词是个不错的选择.何大爷给 出了一种分单词的方法,何大爷认为两个单词是同一类的当这两个单词的 ...
- 国庆 day 2 上午
一道图论神题(god) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,只有 ...
- 国庆 day 6 上午
1. 角谷猜想(kakutani.pas/c/cpp)(kakutani.in/out)时间限制:1s/空间限制:256M[题目描述] 某个名字末尾是 654321 的小 A 同学是个大家眼中公认的学 ...
- 2018国庆YALI集训游记
想了想,像之前那样简略地叙述题意和做法,根本没讲清楚,没有任何意义,还不如写写自己的感受. 感觉YALI真的是一所挺不错的学校吧.总是能有一机房的julao轮番吊打你,总是能有集训队的奆佬来给你出dl ...
- SSH-Struts第三弹:传智播客视频教程第一天上午的笔记
一. 框架概述1.三大框架 : 是企业主流 JavaEE 开发的一套架构 Struts2 + Spring + Hibernate 2. 什么是框架?为什么要学框架 ?框架 是 实现部分功能的代码 ( ...
- JAVA判断当前时间是上午am还是下午pm
//结果为"0"是上午 结果为"1"是下午 public class GregorianTest { public static void main(Strin ...
- PKUSC 模拟赛 day2 上午总结
今天上午考得不是很好,主要还是自己太弱QAQ 开场第一题给的图和题意不符,搞了半天才知道原来是走日字形的 然后BFS即可 #include<cstdio> #include<cstr ...
- PKUSC 模拟赛 day1 上午总结
思考了一下第二题,觉得有无数种乱搞做法 类似什么bitset压位,MCS染色之类奇怪的做法 然而都是玄学正确性或者玄学复杂度 先放题解把 第一题显然具有单调性,二分就可以啦 O(nlogn),貌似输出 ...
- hihoCoder 1041 国庆出游 (DFS)
题意: 小Hi和小Ho准备国庆期间去A国旅游.A国的城际交通比较有特色:它共有n座城市(编号1-n):城市之间恰好有n-1条公路相连,形成一个树形公路网.小Hi计划从A国首都(1号城市)出发,自驾遍历 ...
随机推荐
- HDU 1205 吃糖果(水题)
链接:传送门 思路:思维僵硬了,僵硬...... 简单的插隔板思想......选出来数量最多的糖果种类X,假设X数量为MAX,然后以X作为"隔板",形成X _ X _ X _ X ...
- BZOJ 2342 [SHOI2011]双倍回文 (回文自动机)
题目大意:略 先建出$PAM$ 因为双倍回文串一定是4的倍数,所以找出$PAM$里所有$dep$能整除4的节点 看这个串是否存在一个回文后缀,长度恰好为它的一半,沿着$pre$链往上跳就行了 暴跳可能 ...
- PHP下的Oauth2.0尝试 - OpenID Connect
OpenID Connect OpenID Connect简介 OpenID Connect是基于OAuth 2.0规范族的可互操作的身份验证协议.它使用简单的REST / JSON消息流来实现,和之 ...
- django-3-模板变量,过滤器,静态文件的引用
<<<模板变量>>> (1)定义视图函数 通过context传递参数来渲染模板,context要是个字典 当模板变量为可调用对象的时候,函数不传递参数 (2)配置模 ...
- mybatis中sql标签和include标签
1.首先定义一个sql标签,一定要定义唯一id.(name,age是要查询的字段) <sql id="Base_Column_List" >name,age</s ...
- 【Codeforces Round #482 (Div. 2) C】Kuro and Walking Route
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把x..y这条路径上的点标记一下. 然后从x开始dfs,要求不能走到那些标记过的点上.记录节点个数为cnt1(包括x) 然后从y开始 ...
- CF16A Flag
CF16A Flag 题意翻译 题目描述 根据一项新的ISO标准,每一个国家的国旗应该是一个n×m的格子场,其中每个格子最多有10种不同的颜色.并且国旗应该有条纹:旗帜的每一行应包含相同颜色的方块,相 ...
- 关于android的设备管理器-DevicePolicyManager(一)
在Andorid的设置->安全里面有个设备管理器的选项,相信大部分android用户都不太会去注意这个东西.近期在安装了一个应用之后发现这个里面的东西变了.怎么回事呢,研究研究看看.</s ...
- urlrewrite地址重写的使用
地址重写: 主要是为了站点的安全. 比如我们平时的地址请求 地址重写前,訪问路径是: /read.egov?action=read&bid=2 地址重写后,訪问路径是:/read-read-2 ...
- 从零開始学android<TabHost标签组件.二十九.>
TabHost主要特点是能够在一个窗体中显示多组标签栏的内容,在Android系统之中每一个标签栏就称为一个Tab.而包括这多个标签栏的容器就将其称为TabHost.TabHost类的继承结构例如以下 ...