题目链接: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的更多相关文章

  1. Wannafly Union Goodbye 2016

    A 题意:平面上有n个点(n<=100000),给你一个p(20<=p<=100) 判断是否存在一条直线至少过[np/100](向上取整)个点,时限20s,多组数据 分析:概率算法 ...

  2. 【Mutual Training for Wannafly Union #1 】

    A.Phillip and Trains CodeForces 586D 题意:过隧道,每次人可以先向前一格,然后向上或向下或不动,然后车都向左2格.问能否到达隧道终点. 题解:dp,一开始s所在列如 ...

  3. Mutual Training for Wannafly Union #1解题报告

    ---恢复内容开始--- q神等人组织的vjudge上的多校训练,题目基本上都来自于CF,#1是上周进行的,参加后感觉收获很多,因为上周准备期中比较忙,解题报告现在补上. 比赛地址(兼题目地址) A题 ...

  4. Mutual Training for Wannafly Union #6 E - Summer Trip(并查集)

    题目链接:http://www.spoj.com/problems/IAPCR2F/en/ 题目大意: 给m个数字代表的大小,之后n组数据,两两关联,关联后的所有数字为一组,从小到大输出组数以及对应的 ...

  5. Mutual Training for Wannafly Union #2

    codeforces 298A. Snow Footprints 分类讨论三种情况: ①..RRRRRR…  ②..LLLLLLL… ③..RRRLLLL.. //AC by lwq: #includ ...

  6. Wannafly Union Goodbye 2016-A//初识随机化~

    想来想去还是把这个题写下来了.自己在补题遇到了许多问题. 给出n(n<=1e5)个点,求是否存在多于p(p>=20)×n/100的点在一条直线上... 时限20s,多组数据,暴力至少n^2 ...

  7. 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 ...

  8. Mutual Training for Wannafly Union #9

    A(SPOJ NPC2016A) 题意:给一个正方形和内部一个点,要求从这个点向四边反射形成的路线的长度 分析:不断做对称,最后等价于求两个点之间的距离 B(CF480E) 题意:求01矩阵内由0组成 ...

  9. 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& ...

随机推荐

  1. asp.net/wingtip/显示数据和详细信息

    前边我们的工作处于wingtip工程基础建设阶段,先是建立了“数据访问层”,然后设计建设了“UI和导航”的框架,接下来要充实工程的内容,显示“数据和详细信息”. 一. 添加数据控件(Data Cont ...

  2. 探究高级的Kotlin Coroutines知识

    要说程序如何从简单走向复杂, 线程的引入必然功不可没, 当我们期望利用线程来提升程序效能的过程中, 处理线程的方式也发生了从原始时代向科技时代发生了一步一步的进化, 正如我们的Elisha大神所著文章 ...

  3. Error occurred during initialization of VM Could not reserve enough space for 2097152KB object heap

    ionic build Android后的报错问题 ionic 升级了splashscreen和statusbar的插件后,执行ionic build android会一直报打包错误.原因是过低的An ...

  4. 无法确定条件表达式的类型,因为“<null>”和“System.DateTime”之间没有隐式转换----解决办法

    例子:(报错了) public DateTime? time { get; set; } time = item.HospOutDate.HasValue ? DateTime.Parse(item. ...

  5. Got a packet bigger than‘max_allowed_packet’bytes错误的解决方法

    通常项目上线前都有一些初始化数据需要导入,在今天博客系统发布前我使用sqlyog工具远程登录服务器的Mysql数据库,执行sql脚本对初始数据进行导入的时候报错: Got a packet bigge ...

  6. SQL server 远程连接不成功解决

    一直以来打算自己做一个博客网站,前段时间开始准备做了,正好碰上新睿云服务器免费一年的活动,赶紧拿下.装好了sqlserver ,用本地访问没有问题,但是关键是外网访问一直不行找了好多资料最终才搞定.下 ...

  7. 安装和使用git遇到的问题总结

    一,centos7下安装(因为centos7下用yum安装git的版本太低了,所以只能下载源代码,然后用源代码安装) 下载编译工具 yum -y groupinstall "Developm ...

  8. Ubuntu 把最小化、最大化和关闭按钮放到右边

    1.按下"Ctrl+Alt+T"或者"ALT+F2"调出终端 2.输入"gconf-editor",回车.如果未安装gconf-editor ...

  9. Centos7上安装docker (转)

    Centos7上安装docker Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如 ...

  10. Asp.Net Core 实现服务的批量注册注入