2017多校1 hdu-Balala Power!
其实这道题的思路挺简单的,就是找在第一位置没有出现过并且权值小的那个字母为0.
把a~z按照权值排序,其实难就难在这里,权值很大我们怎么给他排序。
其实可以开个数组来存他们每位数是多少,然后给他们比个大小就好了。
后面排好序就从25开始依次递减
bool cmp(int a, int b) {
for (int i=ans-1; i>=0; i--) {
if (jishu[a][i]!=jishu[b][i]) {
return jishu[a][i]<jishu[b][i];
}
}
return 0;
}
其实就是用一个数组排序来代替那个数的位置
/* gyt
Live up to every day */
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<cstring>
#include<queue>
#include<set>
#include<string>
#include<map>
#include <time.h>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 1e5+;
const ll maxm = 1e7;
const ll mod = ;
const int INF = <<;
const db eps = 1e-;
int vis[];
ll num[maxn];
ll sum[maxn];
ll jishu[][maxn];
ll n,ans,cnt,res,x;
char a[maxn];
int ca=;
void initt() {
num[]=;
for (int i=; i<maxn; i++) {
num[i]=num[i-]*%mod;
}
}
void init() {
ans=,cnt=-,res=,x=;
memset(jishu, , sizeof(jishu));
memset(sum, , sizeof(sum));
memset(vis, , sizeof(vis));
}
bool cmp(int a, int b) {
for (int i=ans-; i>=; i--) {
if (jishu[a][i]!=jishu[b][i]) {
return jishu[a][i]<jishu[b][i];
}
}
return ;
}
void solve() {
initt();
while(scanf("%lld", &n)!=EOF) {
init();
for (int i=; i<n; i++){
scanf("%s", a);
ll len=strlen(a);
if (len>) {
vis[a[]-'a']=;
}
int xx=;
for (int j=len-; j>=; j--) {
int v=a[j]-'a';
jishu[v][xx]++;
sum[v]+=num[xx];
sum[v]%=mod;
int cnt=xx;
xx++;
}
ans=max(ans, len);
}
for(int i=;i<;i++){
for(int j=;j<ans;j++){
jishu[i][j+]+=jishu[i][j]/;
jishu[i][j]%=;
}
while(jishu[i][ans]){
jishu[i][ans+]+=jishu[i][ans]/;
jishu[i][ans++]%=;
}
}
for (int i=; i<; i++) a[i]=i;
sort(a,a+,cmp);;
for (int i=;i<;i++) {
if (!vis[a[i]]) {
cnt=a[i]; break;
}
}
for (int i=; i>=; i--) {
if (a[i]==cnt) continue;
res+=x*sum[a[i]]%mod;
res%=mod;
x--;
}
printf("Case #%d: %lld\n", ca++, res);
} }
int main() {
// freopen("in.txt","r",stdin);
// freopen("kingdom.in","r",stdin);
//freopen("kingdom.out","w",stdout);
int t=;
// scanf("%d", &t);
while(t--) solve();
}
2017多校1 hdu-Balala Power!的更多相关文章
- 2017 多校训练 1002 Balala Power!
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017 多校3 hdu 6061 RXD and functions
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...
- 2017 多校2 hdu 6053 TrickGCD
2017 多校2 hdu 6053 TrickGCD 题目: You are given an array \(A\) , and Zhu wants to know there are how ma ...
- 2017 多校5 hdu 6093 Rikka with Number
2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 & ...
- 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- HDU 6034 - Balala Power! | 2017 Multi-University Training Contest 1
/* HDU 6034 - Balala Power! [ 大数进位,贪心 ] 题意: 给一组字符串(小写英文字母),将上面的字符串考虑成26进制数,每个字母分配一个权值,问这组数字加起来的和最大是多 ...
- HDU 6034 17多校1 Balala Power!(思维 排序)
Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He want ...
- 2017ACM暑期多校联合训练 - Team 1 1002 HDU 6034 Balala Power! (字符串处理)
题目链接 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters. He ...
- HDU 6034 Balala Power!(贪心+排序)
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- hdu 6034 B - Balala Power! 贪心
B - Balala Power! 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6034 题面描述 Talented Mr.Tang has n st ...
随机推荐
- java 连接sqlserver数据库
1.ResultSet executeQuery(String sql):执行某条查询语句并返回结果public static void main(String[] args) throws Exce ...
- CentOS 系统时间与硬件时间
date 系统时间查看 date -s 'YYYYMMDD HHMMSS' 设置系统时间 hwclock 硬件时间查看 hwclock -w 将系统时间同步到硬件时间 cp /usr/share/zo ...
- 最短路+叉积 poj1556
题目链接:The Doors - POJ 1556 - Virtual Judge https://vjudge.net/problem/POJ-1556 题意是叫我们计算从(0,5)到(10,5) ...
- Evaluate Reverse Polish Notation (STRING-TYPE CONVERTION)
Question Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators a ...
- stm32学习基本知识点
1.AHB系统总线分为APB1(36MHz)和APB2(72MHz),其中2>1,意思是APB2接高速设备 2.Stm32f10x.h相当于reg52.h(里面有基本的位操作定义),另一个为st ...
- 【php 之根据函数名称动态调用该函数】
解释函数:call_user_func()以及函数call_user_func_array() 对于PHP程序员而言,函数是再熟悉不过的事物了,毕竟我们整天都在和PHP内置函数以及我们自定义的函数打交 ...
- 使用命令行执行sql文件
用Navicat 导入sqlserver数据库时,出现了out of memory异常,百度无果,想起之前用命令行导入过,再次试了一下成功 用法: 打开执行命令: sqlcmd -S localhos ...
- [leetcode]210. Course Schedule II课程表II
There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prereq ...
- [leetcode]791. Custom Sort String自定义排序字符串
S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...
- linux操作系统重启后 解决nginx的pid消失问题
重启了linux服务器之后,进程性的 nginx -s stop后再次启动nginx -s reload ,总是会报错误nginx: [error] open() "/alidata/ser ...