http://soj.me/8843

题意:几个人想做好朋友,朋友之间相差位置小于等于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的更多相关文章

  1. POJ 1815 Friendship

    Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissions: 10626   Accepted: 2949 Descr ...

  2. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  3. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  4. [IR] Ranking - top k

    PageRanking 通过: Input degree of link "Flow" model - 流量判断喜好度 传统的方式又是什么呢? Every term在某个doc中的 ...

  5. Friendship

    Friendship Time Limit: 2000MS Memory Limit: 20000K Total Submissions: 9824 Accepted: 2720 Descriptio ...

  6. JSU 2013 Summer Individual Ranking Contest - 5

    JSU 2013 Summer Individual Ranking Contest - 5 密码:本套题选题权归JSU所有,需要密码请联系(http://blog.csdn.net/yew1eb). ...

  7. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  8. 大数求模 sicily 1020

        Search

  9. PAT Ranking (排名)

    PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...

随机推荐

  1. 使用AlarmManager定期执行工作

    新建一个Service来模拟后台执行的程序,PollingService.java: package com.ryantang.rtpollingdemo; import android.app.No ...

  2. The sixth day

    bound to 铁定You are bound to be fired  你会被铁定开除的 A:Dan forgot his map? Dan忘了带地图了吗? B:Yep!And he's boun ...

  3. 【干货】Html与CSS入门学习笔记1-3

    从23号开始用了4天时间看完了<Head First Html与CSS>这本书,本书讲解方式深入浅出,便于理解,结合习题,便于记忆,是一本不错的入门书.下面是本书的学习笔记: 一.认识HT ...

  4. SQL Server 08版与14版处理重复行的方式

    在项目中,利用循环拼接成了插入多行数据的SQL语句: Insert into table(col1,col2)vaules(value11,value21); Insert into table(co ...

  5. Win 10 Google 云端硬盘 网页证书问题导致无法登录解决办法

    操作方法 按照图示,将以下3项勾去并确定. 效果 设置以后,可成功访问:

  6. java Vamei快速教程05 实施接口

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在封装与接口中,private关键字封装了对象的内部成员.经过封装,产品隐藏了内部 ...

  7. 【翻译】22款HTML & CSS3 UI工具包免费下载

    下面盘点了22款适用于网页设计的HTML&CSS3 UI工具包,并且全部都是免费的哦!喜欢就赶紧 下载或收藏吧.这些免费工具可以加速你的网页开发进程,让你有更多时间专注于其他更重要的部分.由于 ...

  8. IOS 偏好设置数据 存 取(Preferences文件夹)

    很多iOS应用都支持偏好设置,比如保存用户名.密码.字体大小等设 置,iOS提供了一套标准的解决方案来为应用加入偏好设置功能 每个应用都有个NSUserDefaults实例,通过它来存取偏好设置 比如 ...

  9. Android(java)学习笔记152:采用get请求提交数据到服务器(qq登录案例)

    1.GET请求:    组拼url的路径,把提交的数据拼装url的后面,提交给服务器. 缺点:(1)安全性(Android下提交数据组拼隐藏在代码中,不存在安全问题)  (2)长度有限不能超过4K(h ...

  10. 2018.5.22 Oracle安装配置在虚拟机中外部电脑连接服务

    1.拷贝老师的集成文件(win系统和oracle服务) 2.安装虚拟机,并且打开镜像文件 3.启动监听程序(实例服务[自动].监听服务) 4.查看虚拟机ip,此ip要主机ip在同一个网段 5.检查虚拟 ...