Wannafly Union#1
题目链接:http://vjudge.net/contest/142053#overview
A.题意:有一个3*n的隧道,人和车轮流走,人先向右走一步,然后选在是在原地不动还是上下移动一格,之后车开始往左移两格,问人是否能走到隧道尽头
思路:车是不会上下动的,那么我们按照相对来算就行,也就是人相当于往右走一步,然后选择不动还是上下移动一格,然后往右走两步。bfs处理把能走到的点加入到队列
bfs和dp其实思路是一样的,都是从左到右递推过去的
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <queue>
using namespace std;
char G[][];
bool flag[][];
int n;
bool vis;
struct node{
int x,y;
};
bool judge(int x,int y){
return G[x][y]=='.';
}
bool ok(node &temp){
if(judge(temp.x,temp.y)){
if(judge(temp.x,temp.y+)){
if(temp.y+==n) vis=true;
}
if(judge(temp.x,temp.y+)&&judge(temp.x,temp.y+)){
if(temp.y+==n||temp.y+==n) vis=true;
}
if(judge(temp.x,temp.y+)&&judge(temp.x,temp.y+)){
temp.y+=;
if(!flag[temp.x][temp.y]){
return true;
}
}
}
return false;
}
bool bfs(int posx,int posy){
memset(flag,false,sizeof(flag));
queue<node> q;
vis=false;
while(!q.empty()) q.pop();
node e;
e.x=posx,e.y=posy;
q.push(e);
flag[e.x][e.y]=true;
while(!q.empty()){
node tmp=q.front();
q.pop();
if(tmp.y==n) return true;
else {
node temp,tmpup,tmpdown;
temp=tmp;
temp.y=tmp.y+;
if(!judge(temp.x,temp.y)) continue;
if(temp.y==n) return true;
tmpup=temp,tmpup.x+=;
tmpdown=temp,tmpdown.x-=;
if(ok(temp)){
q.push(temp);
flag[temp.x][temp.y]=true;
}
if(ok(tmpup)){
q.push(tmpup);
flag[tmpup.x][tmpup.y]=true;
}
if(ok(tmpdown)){
q.push(tmpdown);
flag[tmpdown.x][tmpdown.y]=true;
}
if(vis) return true;
}
}
return false;
}
void solve(int T){
int k;
scanf("%d %d",&n,&k);
int x,y;
for(int i=;i<=;i++){
for(int j=;j<=n;j++){
scanf(" %c",&G[i][j]);
if(G[i][j]=='s') {
x=i,y=j;
}
}
}
if(bfs(x,y)){
printf("YES\n");
}
else
printf("NO\n");
return ;
}
int main(){
int T;
while(scanf("%d",&T)!=EOF){
for(int i=;i<=T;i++) solve(i);
}
}
B.题意:有一个字符串,看能不能在字符串的任意位置插入一个字符串使得这个字符串是回文串
思路:水题,暴力插入
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
char str[];
char tmp[];
bool judge(int len){
for(int i=;i<=len;i++){
if(tmp[i]!=tmp[len-i]){
return false;
}
}
return true;
}
void solve(){
int len=strlen(str);
for(int i=;i<=len;i++){
for(int j=;j<;j++){
tmp[i]='a'+j;
for(int k=;k<i;k++) tmp[k]=str[k];
for(int k=i+;k<=len;k++) tmp[k]=str[k-];
if(judge(len)){
for(int k=;k<=len;k++){
printf("%c",tmp[k]);
}
printf("\n");
return ;
}
}
}
printf("NA\n");
return ;
}
int main(){
while(scanf("%s",str)!=EOF){
solve();
}
return ;
}
D.题意:有一个n*n的棋盘,白棋在(1,1),黑棋(1,n),其余的地方都是绿棋子,棋子的走法和国际象棋里面的皇后一样,白棋和黑棋走的路上必须吃子
当某个棋子不能吃子或者被对手吃了就算输了,输出谁输,如果白棋赢输出白棋走的第一步,l和c都尽量小
思路:如果棋盘是奇数的话,白棋先手,黑棋走白棋的镜像,这样的话相当于当白棋走到中间时,黑棋总能把它吃掉。
如果棋盘是偶数的话,白棋先手走(1,2)这样相当于把棋盘变成奇数并且黑棋先手了,那样黑棋必输,而白棋总能通过先走(1,2)来赢
#include <stdio.h>
int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n&)printf("black\n");
else {
printf("white\n1 2\n");
}
}
return ;
}
F:题意:有很多个约束条件,输出满足约束条件的任意一个数
思路:设一个l,r表示上界和下界,不断夹就行,矛盾就不行(代码有点丑QwQ)
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
char str[];
int num;
char type[];
void solve(int T){
int l=-2e9;
int r=2e9;
bool flag=true;
while(T--){
scanf("%s%d%s",str,&num,type);
if(type[]=='N'){
if(str[]=='>'){
if(str[]=='='){
if(num-<l){
flag=false;
continue;
}
r=min(r,num-);
}
else {
if(num<l) {
flag=false;
continue;
}
r=min(r,num);
}
}
if(str[]=='<'){
if(str[]=='='){
if(num+>r){
flag=false;
continue;
}
l=max(l,num+);
}
else {
if(num>r){
flag=false;
continue;
}
l=max(num,l);
}
}
}
else {
if(str[]=='>'){
if(str[]=='='){
if(num>r){
flag=false;
continue;
}
l=max(l,num);
}
else {
if(num+>r){
flag=false;
continue;
}
l=max(num+,l);
}
}
if(str[]=='<'){
if(str[]=='='){
if(num<l) {
flag=false;
continue;
}
r=min(r,num);
}
else {
if(num-<l){
flag=false;
continue;
}
r=min(r,num-);
}
}
}
}
if(!flag){
printf("Impossible\n");
return ;
}
for(int i=l;i<=r;i++){
printf("%d\n",i);
return ;
} }
int main(){
int T;
while(scanf("%d",&T)!=EOF){
solve(T);
}
}
E题填坑来了
题意:有一个n*n的方格,里面有m个棋子,每个棋子有自身的属性值p,现在有这样一个集合,集合内的棋子要满足都在一条斜线上,并且距离(斜线上的距离)要满足一个条件,dis(i,j)>=pi^2+pj^2+C(C为常数)
思路:假设xi>xj,那么dis(i,j)=xi-xj+1 xi-xj+1>=pi^2+pj^2+C ---> xi-pi^2>=xj+pj^2+C-1 假设左边为A[i],右边为B[i],这样每个点都有属性ai,bi,把每条斜线按照x的升序排列,然后用类似nlogn求LIS的方法求出每条斜线上最多,我设a=x-p^p b=x+p^p+c-1,那么肯定B[i]>A[i],也就是如果你在序列中找到了这个点插入的位置,就可以直接插入,因为B[i]不可能在前面
能在集合里面加几个点假设xi>xj>xk 那么dis(i,k)=dis(i,j)+dis(j,k)-1>=pi^2+2*pj^2+pk^2+2*C-1>pi^2+pk^2+C 也就是只要相邻的满足条件,那么这个点肯定跟整个集合里面的满足条件
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
const int maxn=1e5+;
int n,m,C;
struct node{
long long x,y,p;
node(){};
long long a,b;
node(int x_,int y_,int p_):x(x_),y(y_),p(p_){
a=x-p*p,b=x+p*p+C-;
}
};
vector<node> G1[*maxn];
vector<node> G2[*maxn];
set<int> s1;
set<int> s2;
set<int> ::iterator it;
int siznum;
bool cmp(const node&tmp1,const node&tmp2){
return tmp1.x<tmp2.x;
}
int ans=;
long long q[maxn];
void cal(vector<node> G[*maxn],set<int> s){
for(it=s.begin();it!=s.end();it++){
int num=*it;
int cnt=;
sort(G[num].begin(),G[num].end(),cmp);
for(int i=;i<G[num].size();i++){
int pos=upper_bound(q,q+cnt,G[num][i].a)-q;
if(pos==cnt){
q[cnt++]=G[num][i].b;
}
else {
if(q[pos]>G[num][i].b){
q[pos]=G[num][i].b;
}
}
}
ans=max(ans,cnt);
}
}
node point[maxn];
long long num[maxn<<];
void solve(){
ans=;
scanf("%d %d %d",&n,&m,&C);
for(int i=;i<(*maxn);i++) G1[i].clear(),G2[i].clear();
s1.clear(),s2.clear();
long long x,y,p;
for(int i=;i<=m;i++){
scanf("%lld %lld %lld",&x,&y,&p);
point[i]=node(x,y,p);
s1.insert(x+y);
s2.insert(y-x+maxn);
G1[x+y].push_back(point[i]);
G2[y-x+maxn].push_back(point[i]);
}
cal(G1,s1);
cal(G2,s2);
printf("%d\n",ans);
}
int main(){
int T;
freopen("bishops.in","r",stdin);
scanf("%d",&T);
while(T--){
solve();
}
}
C题放弃QAQ
非常感激大佬们挂题讲题QAQ
Wannafly Union#1的更多相关文章
- Wannafly Union Goodbye 2016
A 题意:平面上有n个点(n<=100000),给你一个p(20<=p<=100) 判断是否存在一条直线至少过[np/100](向上取整)个点,时限20s,多组数据 分析:概率算法 ...
- 【Mutual Training for Wannafly Union #1 】
A.Phillip and Trains CodeForces 586D 题意:过隧道,每次人可以先向前一格,然后向上或向下或不动,然后车都向左2格.问能否到达隧道终点. 题解:dp,一开始s所在列如 ...
- Mutual Training for Wannafly Union #1解题报告
---恢复内容开始--- q神等人组织的vjudge上的多校训练,题目基本上都来自于CF,#1是上周进行的,参加后感觉收获很多,因为上周准备期中比较忙,解题报告现在补上. 比赛地址(兼题目地址) A题 ...
- Mutual Training for Wannafly Union #6 E - Summer Trip(并查集)
题目链接:http://www.spoj.com/problems/IAPCR2F/en/ 题目大意: 给m个数字代表的大小,之后n组数据,两两关联,关联后的所有数字为一组,从小到大输出组数以及对应的 ...
- Mutual Training for Wannafly Union #2
codeforces 298A. Snow Footprints 分类讨论三种情况: ①..RRRRRR… ②..LLLLLLL… ③..RRRLLLL.. //AC by lwq: #includ ...
- Wannafly Union Goodbye 2016-A//初识随机化~
想来想去还是把这个题写下来了.自己在补题遇到了许多问题. 给出n(n<=1e5)个点,求是否存在多于p(p>=20)×n/100的点在一条直线上... 时限20s,多组数据,暴力至少n^2 ...
- Mutual Training for Wannafly Union #8 D - Mr.BG Hates Palindrome 取余
Mr.BG is very busy person. So you have been given enough time (1000 milliseconds) to help him. Mr. B ...
- Mutual Training for Wannafly Union #9
A(SPOJ NPC2016A) 题意:给一个正方形和内部一个点,要求从这个点向四边反射形成的路线的长度 分析:不断做对称,最后等价于求两个点之间的距离 B(CF480E) 题意:求01矩阵内由0组成 ...
- Mutual Training for Wannafly Union #6
A =w= B QvQ C 题意:有长度为n的序列(n<=5e5),求满足条件的a,b,c,d的组数,要求满足条件:min([a,b])<=min([c,d]),a<=b<c& ...
随机推荐
- 自定义HorizontalScrollView的scrollBar
尊重劳动成果,转载请标明出处http://www.cnblogs.com/tangZH/p/8423803.html android滑动组件的scrollBar,看了不是很顺眼,没办法,因为项目需求, ...
- angular应用容器化部署
angular 应用容器化部署 Intro 我自己有做一个个人主页,虽然效果不怎么样(不懂设计的典型程序猿...),但是记录了我对于前端框架及工具的一些实践, 从开始只有一个 angularjs 制作 ...
- redis 慢日志查询
Intro 可能有一些命令需要很长时间才能在redis服务器上处理,导致请求超时. 长时间运行的命令的很少例子有 mget有大量的键,键*或写得不好的lua脚本. 可以运行通过 SlowLog 命令查 ...
- SQL Server 2008初次启动
一.关于安装 SQL Server 数据库的安装,经过自己的安装,总体还是比较容易,没有太多难度,安装包在网上也有很多,在此,就跳过安装的这一步. 二.初次启动SQL Server 安装完成数据库后, ...
- 生成Csv格式的字符串
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...
- Redis学习笔记(3)——Redis的命令大全
Redis是一种nosql数据库,常被称作数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Map), 列表(list), 集合(sets) 和 有序集合(sorted se ...
- RPC是什么?
初学微服务,一点会问RPC是什么,通常网上的资料会说,是一种协议,然后说得很复杂,一堆概念,拜托,我只是想知道RPC是什么,而不是 怎么实现怎么做. RPC就是想实现函数调用模式的网络化,A服务(微 ...
- 【alpha阶段】第一次Scrum Meeting
每日任务内容 队员 昨日完成任务 明日要完成的任务 牛宇航 #2 数据库重构https://github.com/rRetr0Git/rateMyCourse/issues/2 #8 后端函数修正及重 ...
- mysq基础操作
创建表: create table customer(mid char(5) primary key,name varchar(20),birth date,sex char(1) DEFAULT ' ...
- Day7 Numerical simulation of optical wave propagation之通过随机介质(如大气湍流)的传播(三)
三 执行湍流仿真 基本参数设置: 光场条件:波长wvl,源平面的光场U 传播几何结构:观察面孔径尺寸D2,传播距离Dz 湍流条件:大气折射率结构常数Cn2 1. 准备工作 确定传播几何结构 (程序: ...