Sicily 8843 Ranking and Friendship
题意:几个人想做好朋友,朋友之间相差位置小于等于k,且长度相同
分析;排序,将长度相同的放在一起。若长度相同,第i个人能放进去的条件是位置相差下雨等于k。
若不能放进去,将对头踢掉,踢到对头是第i个人的朋友的时候为止。若长度不相同,则将队列清空。
更新sum值,在第i个人进去的时候就加上队列的当前长度。
这个没考虑的问题是当长度相同,但是队列中的人都不符合其位置差,全部剔除的时候,第i个人却没有加进队列,导致错误
// Problem#: 8842
// Submission#: 2269282
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
// Problem#: 8842
// Submission#: 2269196
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
/*#include<stdio.h>
#include<string.h>
const int MN=110;
int vis[MN][MN];
char str[MN][MN];
int n,m;
int A,B,C,D,E;
int row[]= {-1,1,0,0};
int col[]= {0,0,-1,1};
int num1[200];
int num2[200];
struct Node
{
int x,y;
} s,e; void DFS(int x,int y,char flag)
{
for(int i=0; i<4; i++)
{
int xx=x+row[i];
int yy=y+col[i];
if(xx>=1 && xx<=n && yy>=1 && yy<=m && str[xx][yy]!='X' && vis[xx][yy]==0)
{
if(str[xx][yy]==flag)
{
num2[flag]++;
}
}
}
}
void work(int i,int j)
{
if(str[i][j]=='S')
{
s.x=i;
s.y=j;
}
else if(str[i][j]=='G')
{
e.x=i;
e.y=j;
}
num1[str[i][j]]++;
} int main()
{
int i,j;
while(scanf("%d%d",&n,&m))
{
A=B=C=D=E=0;
for(i=1; i<=n; i++)
{
scanf("%s",str[i]+1);
for(j=1; j<=m; j++)
{
work(i,j);
}
}
for(char t='a'; t<='e'; t++)
{
DFS(s.x,s.y,t);
if(num2[t]==num1[t])
{
DFS2()
}
}
}
return 0;
}*/ #include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
#define LL long long
const int MN=; struct Node
{
char nam[];
int len;
int pos;
} node[MN]; queue<int>Q; bool cmp(Node a,Node b)
{
if(a.len!=b.len) return a.len<b.len;
return a.pos<b.pos;
} int main()
{
int n,k,i,j;
int ans;
while(scanf("%d%d",&n,&k)!=EOF)
{
getchar();
while(!Q.empty()) Q.pop();
for(i=; i<=n; i++)
{
gets(node[i].nam);
node[i].len=strlen(node[i].nam);
node[i].pos=i;
}
sort(node+,node+n+,cmp);
long long sum=;
int length=;
Q.push();
int t;
for(i=; i<=n; i++)
{
t=Q.front();
if(node[t].len!=node[i].len)
{
while(!Q.empty()) Q.pop();
length=;
Q.push(i);
}
else
{
if(node[i].pos-node[t].pos<=k)
{
Q.push(i);
sum+=length;
length++;
}
else
{
while(!Q.empty())
{
t=Q.front();
if(node[i].pos-node[t].pos<=k)
{
Q.push(i);
sum+=length;
length++;
break;
}
else
{
Q.pop();
length--;
if(Q.empty())
{
Q.push(i);
length=;
break;
}
}
}
}
}
}
printf("%lld\n",sum);
}
return ;
}
Sicily 8843 Ranking and Friendship的更多相关文章
- POJ 1815 Friendship
Friendship Time Limit: 2000MS Memory Limit: 20000K Total Submissions: 10626 Accepted: 2949 Descr ...
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- [IR] Ranking - top k
PageRanking 通过: Input degree of link "Flow" model - 流量判断喜好度 传统的方式又是什么呢? Every term在某个doc中的 ...
- Friendship
Friendship Time Limit: 2000MS Memory Limit: 20000K Total Submissions: 9824 Accepted: 2720 Descriptio ...
- JSU 2013 Summer Individual Ranking Contest - 5
JSU 2013 Summer Individual Ranking Contest - 5 密码:本套题选题权归JSU所有,需要密码请联系(http://blog.csdn.net/yew1eb). ...
- HDU 5578 Friendship of Frog 水题
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- 大数求模 sicily 1020
Search
- PAT Ranking (排名)
PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...
随机推荐
- 什么是Spring
之前已经学习过web三层(数据库链接层dao,业务逻辑控制层service,用户层web). 在开发过程中,我们不断引入更加优秀的工具的目的都是在安全.高效的基础上,简化开发,和易于维护. 所以引入s ...
- window mysql5.7 zip 安装
第一步 ? 1 2 3 4 5 6 7 8 9 10 11 12 my-default.ini 添加配置: #绑定IPv4和3306端 bind-address = 127.0.0.1 port = ...
- Keymob带你玩转新广告法下的移动营销
2015年9月1日新广告法正式实施,对广告代言人.广告类别.广告语等都做了一系列新规定,堪称有史以来最严广告法.随着新广告法的实施,以往一些庸俗.夸张的广告也逐渐和大众说再见了. 2015年 “互联网 ...
- 阻止Bootstrap 模态框(Modal)点击空白处时关闭
默认情况下点击空白处时会关闭模态框,添加data-backdrop="static"后可以阻止关闭
- vue+node+mongodb实现的页面
源代码地址:https://github.com/GainLoss/vue-node-mongodb 目前这个项目实现的是: 1.利用vue-cli实现前台页面的编写 (1)页面的跳转利用的是vue- ...
- java Vamei快速教程18 容器
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Java中有一些对象被称为容器(container).容器中可以包含多个对象,每个 ...
- IBM WebSphere MQ安装及配置详解
打开MQ安装程序,选择下一步,默认安装WebSphere MQ, 完成MQ的安装工作,启动WebSphere MQ, 服务器配置,选择新建队列管理器,创建名为 "mq"的队列管理器 ...
- js 正则匹配(去掉html标签)
正则匹配去掉所有html标签 var a = "<span>999</span>" a = a.replace(/<[^>]+>/g,' ...
- IOS 获取手机的屏幕宽度
//屏幕的宽度 CGFloat screenW=[UIScreen mainScreen].bounds.size.width;
- SpringMVC+Hibernate框架快速搭建
1. 新建Maven项目springmvc 2. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" ...