很简单的题,主要是要用字符串哈希,把字符串处理成整数。接下来可以继续用hash,也可以像我一样用个map就搞定了。

/*
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef long long LL;
/*
* 输入非负整数
* 支持short、int、long、long long等类型(修改typec即可)。
* 用法typec a = get_int();返回-1表示输入结束
*/
typedef int typec;
typec get_int() {
typec res = , ch;
while (!((ch = getchar()) >= '' && ch <= '')) {
if (ch == EOF)
return -;
}
res = ch - '';
while ((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
return res;
}
//输入整数(包括负整数,故不能通过返回值判断是否输入到EOF,本函数当输入到EOF时,返回-1),用法int a = get_int2();
int get_int2() {
int res = , ch, flag = ;
while (!((ch = getchar()) >= '' && ch <= '')) {
if (ch == '-')
flag = ;
if (ch == EOF)
return -;
}
res = ch - '';
while ((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
if (flag == )
res = -res;
return res;
}
/**
* 输入一个字符串到str中,与scanf("%s", str)类似,
* 会忽略掉缓冲区中的空白字符。返回值为输入字符串
* 的长度,返回-1表示输入结束。
*/
int get_str(char *str) {
char c;
while ((c = getchar()) <= ' ') {
if(c == EOF) {
return -;
}
}
int I = ;
while (c > ' ') {
str[I++] = c; c = getchar();
}
str[I] = ;
return I;
} int hash_code(const char str[]) {
int h = ;
for (int i = ; str[i] > ; i++) {
h = * h + str[i];
}
return h;
} int main() {
int N = get_int();
char str[];
map<int, int> mymap;
for (int i = ; i < N; i++) {
get_str(str);
int len = strlen(str);
sort(str, str + len);
int hash = hash_code(str);
if (mymap.count(hash) > ) {
printf("%d\n", mymap[hash]++);
} else {
printf("0\n");
mymap[hash] = ;
}
}
return ;
}

百度之星2016资格赛D,水题的更多相关文章

  1. 百度之星IP聚合(水题map&字符处理)

    虽然题目停水的,但是好像字符处理运用的还比较合适 Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊 ...

  2. BestCoder 百度之星2016

    20160523 百度之星初赛第一场 1001 All X Problem Description F(x, m)F(x,m) 代表一个全是由数字xx组成的mm位数字.请计算,以下式子是否成立: F( ...

  3. 51nod百度之星2016练习赛

    今天看了看51nod发现有这样一个练习赛,就做了做.因为实力太弱想不出E题,各位神犇勿D. (5.26UPD:E题想粗来了) A 区间交 不难发现若干线段[li,ri]的交就是[max(li),min ...

  4. [百度之星2014资格赛] Disk Schedule 报告

    Disk Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  5. 百度之星2014资格赛 1003 - Xor Sum

    先上代码: Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)T ...

  6. 百度之星2014资格赛 1004 - Labyrinth

    先上题目: Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. HDU 5688:2016"百度之星" - 资格赛 Problem D

    原文链接:https://www.dreamwings.cn/hdu5688/2650.html Problem D Time Limit: 2000/1000 MS (Java/Others)    ...

  8. 2016百度之星 资格赛ABCDE

    看题:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 交题:http://acm.hdu.edu.cn/search.php ...

  9. HDU 5686:2016"百度之星" - 资格赛 Problem B

    原文链接:https://www.dreamwings.cn/hdu5686/2645.html Problem B Time Limit: 2000/1000 MS (Java/Others)    ...

随机推荐

  1. 【CF1017C】The Phone Number(构造)

    题意:要求构造一个1-n的排列,使得它的LIS+LDS最小 n<=1e5 思路:一个百度之星时候从LYY处听来的结论:1-n随机排列的LIS期望是根号级别的 考虑将LIS与LDS都构造成根号级别 ...

  2. UML系列,使用UML实现GOF Design patterns,常用模式类图解读

    1.单例:Singleton, DirectedAssociation

  3. gulp前端自动化入门

    一.从零开始搭建gulp前端自动化 1.首先安装nodejs 2.npm init 初始化 生成package.json 2.1 可以选装cnpm cnpm是淘宝提供的服务 安装:命令提示符执行npm ...

  4. Java后端WebSocket的Tomcat实现 html5 WebSocket 实时聊天

    WebSocket协议被提出,它实现了浏览器与服务器的全双工通信,扩展了浏览器与服务端的通信功能,使服务端也能主动向客户端发送数据.Tomcat7.0.47上才能运行. 需要添加Tomcat里lib目 ...

  5. 小程序 之登录 wx.login()

    小程序的登录关键在于使用wx.login()方法后,要到取到code值传到后台, 再用小程序平台本帐号生成的appid+addsecret+code去微信接口服务取得用户唯一标识后即可登录[注意:此步 ...

  6. jquery 分页功能

    <div class="wrapper"> <div class="row"> <div class="col-sm-1 ...

  7. 洛谷——P1078 文化之旅

    P1078 文化之旅 题目描述 有一位使者要游历各国,他每到一个国家,都能学到一种文化,但他不愿意学习任何一种文化超过一次(即如果他学习了某种文化,则他就不能到达其他有这种文化的国家).不同的国家可能 ...

  8. VirtualApp技术黑产利用研究报告

    一. 前言 VirtualApp(以下称VA)是一个App虚拟化引擎(简称VA).VirtualApp创建了一个虚拟空间,你可以在虚拟空间内任意的安装.启动和卸载APK,这一切都与外部隔离,如同一个沙 ...

  9. List&lt;InvestInfoDO&gt; invest = advertiseDao6.qryInvestInfo(InvestInfoDO1);怎样获得list的实体类;

    List<InvestInfoDO>  invest = advertiseDao6.qryInvestInfo(InvestInfoDO1); 怎样获得List的实体类呢,就是怎样获得I ...

  10. 使用Cout输出String和CString对象

    CString和string都是一个类,不同的是CString主要用于MFC或者是ATL编程中,而string则多用于Windows控制台编程中 在实际编程过程中,我们经常用到string或者是CSt ...