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. android打开文件、保存对话框、创建新文件夹对话框(转载)

    转载地址:点击打开 这是一个简单的只有3个按钮的程序,3个按钮分别对应三种工作的模式(保存.打开和文件夹选择).封装的SimpleFileDialog.java的内容如下: package com.e ...

  2. Android Service创建USB HOST通信

    之前做了一个关于Android USB通信的Case,通过Android的USB总线给Zigbee供电,和板载的Zigbee(基于Zigbee的自组网)进行通信.要使用Android的USB Host ...

  3. css禁止文字被选中

    有时候,为了让用户有更好的体验,需要禁用掉文本选中功能 比如:使用a标签模拟按钮,如果不禁用掉文本选中功能,那么双击时会选中文字,用起来很不爽. 多数情况下,只需要使用CSS样式就可以实现这个功能啦: ...

  4. Python开发环境Wing IDE如何使用调试功能

    在使用Wing IDE开始调试的时候,需要设置断点的行,读取GetItemCount函数的返回.这可以通过单击行并选择Break工具栏条目,或通过单击行左边的黑色边缘.断点应该以实心红圈的形式出现: ...

  5. LeetCode OJ Container With Most Water 容器的最大装水量

    题意:在坐标轴的x轴上的0,1,2,3,4....n处有n+1块木板,长度不一,任两块加上x轴即可构成一个容器,其装水面积为两板的间距与较短板长之积,以vector容器给出一系列值,分别代表在0,1, ...

  6. linux 命令——56 netstat(转)

    netstat命令用于显示与IP.TCP.UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况.netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP ...

  7. json字符串转换成对象需要注意的问题

    json转换成对象的时候应该尽量避免出现特殊的符号,如“\”这样的字符在转义成数组的时候会被去除掉,最好的例子就是后台返回的内容为存储路径的JSON,这时候最好是把一个斜杠变为两个斜杠,如: [{&q ...

  8. POI 怎么设置Excel整列的CellStyle啊

    POI 怎么设置Excel整列的CellStyle啊,而不是循环每个Cell.因为现在是生成Excel模板,不知道客户会输入多少行. 问题补充: 指尖言 写道 好像没有这个方法,CellStyle是C ...

  9. 使用Scanner类获取键盘输入的会员卡号,并将该数据存储在变量中,输出这个变量的信息

    package come.one01;import java.util.Scanner; // 导入Scanner类public class One03 { public static void ma ...

  10. 转:Python字典与集合操作总结

    转自:http://blog.csdn.net/business122/article/details/7537014 一.创建字典 方法①: >>> dict1 = {} > ...