【题目描述】

寒枫将军将要带领他的部队去圣雪山消灭那里的冰龙。

部队分成了若干个小队,属于同一个小队的人兵种相同。寒枫将军有着杰出的指挥能力,在战斗的时候,寒枫将军能够让所有相同兵种的人互相配合,使t个相同兵种的人发挥出t2的战斗力;寒枫将军还能让不同兵种的人互相配合,使整个部队的战斗力是所有兵种战斗力的和。

例如,部队中有3个小队,分别是5个人的步兵小队,3个人的步兵小队,3个人的骑兵小队。那么步兵战斗力为64,骑兵战斗力为9,部队总战斗力为73。

寒枫将军需要知道他的部队的战斗力是多少。

【输入格式】

第一行一个整数n,表示小队数。接下来n行,第i行有两个整数ai、bi,表示这个小队有ai个人,兵种为bi

【输出格式】

一行一个整数,部队的战斗力。

【样例输入】

3

5 1

3 1

3 2

【样例输出】

73

【数据规模与约定】

10%的数据,n=1

30%的数据,n≤1000

另有20%的数据,ai=1

另有30%的数据,bi≤1000

100%的数据,1≤n≤100000,1≤ai≤10000,1≤bi≤1,000,000,000

直接用map做就可以。

题解:是以b为关键字排序,然后捋一遍求出答案。时间复杂度(O(nlogn))

代码实现:

我的:

 #include<map>
#include<cstdio>
#include<iostream>
using namespace std;
int n,l,s[],b;
long long a,ans;
map <int,long long> v;
int main(){
freopen("expedition.in","r",stdin);
freopen("expedition.out","w",stdout);
cin>>n;
for(int i=;i<n;i++){
cin>>a>>b;
if(!v[b]) s[l++]=b;
v[b]+=a;
}
for(int i=;i<l;i++) ans+=v[s[i]]*v[s[i]];
cout<<ans<<endl;
return ;
}

std:

 #include<cstdio>
#include<algorithm>
using namespace std;
const int N = ;
int n;
struct Info
{
int num,kind;
}xu[N];
bool cmp(Info x,Info y)
{
return(x.kind<y.kind);
}
int main()
{
freopen("expedition.in","r",stdin);
freopen("expedition.out","w",stdout);
int i;
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d%d",&xu[i].num,&xu[i].kind);
sort(xu+,xu+n+,cmp);
long long ans=;
for(i=;i<=n;i++)
{
long long now=xu[i].num;
while(i<n && xu[i].kind==xu[i+].kind)
{
i++;
now+=xu[i].num;
}
now*=now;
ans+=now;
}
printf("%I64d\n",ans);
return ;
}

大概敲了不到半个小时,可以接受。

远征(expedition)的更多相关文章

  1. POJ 2431 Expedition(优先队列、贪心)

    题目链接: 传送门 Expedition Time Limit: 1000MS     Memory Limit: 65536K 题目描述 驾驶一辆卡车行驶L单位距离.最开始有P单位的汽油.卡车每开1 ...

  2. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  3. poj 2431 Expedition

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12980   Accepted: 3705 Descr ...

  4. POJ 2431 Expedition (STL 优先权队列)

    Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8053   Accepted: 2359 Descri ...

  5. Expedition(优先队列)

    Expedition 点我 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9465   Accepted: 2760 Des ...

  6. poj 3431 Expedition 优先队列

    poj 3431 Expedition 优先队列 题目链接: http://poj.org/problem?id=2431 思路: 优先队列.对于一段能够达到的距离,优先选择其中能够加油最多的站点,这 ...

  7. CF1091F New Year and the Mallard Expedition

    题目地址:CF1091F New Year and the Mallard Expedition 题意比较复杂,整理一下: \(n\) 段,每段有两个属性:长度,地形(G,W,L) 有三种运动方式: ...

  8. H - Expedition 优先队列 贪心

    来源poj2431 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being ...

  9. Planning The Expedition(暴力枚举+map迭代器)

    Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...

随机推荐

  1. Luogu P2073 送花

    权值线段树的模板题 然而AC后才发现,可以用\(\tt{set}\)水过-- 权值线段树类似于用线段树来实现平衡树的一些操作,代码实现还是比较方便的 #include<iostream> ...

  2. cesium底图加载底图切换 基于天地图服务

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. sphinx关键字套红

    sphinx定义搜索结果,搜索的内容着重显示,可以使用下面代码 <?php /** * Created by PhpStorm. * User: pc00001 * Date: 2015/4/1 ...

  4. python--以1-31的数字作为结尾的列表?论英文好的重要性!

    一.python基础教程第2板(修订版)[代码清单2-1]中有一段要求打印‘以1-31的数字作为结尾的列表’ 截取代码示例:endings =['st','nd','rd'] +17*['th'] + ...

  5. python入门:py2.x里面除法或乘法这么写就可以计算小数点后面结果

    #!/usr/bin/env python # -*- coding:utf-8 -*- #py2.x里面除法或乘法这么写就可以计算小数点后面结果,更精确future(未来,译音:非忧车) divis ...

  6. Vue中引入TradingView制作K线图

    **前言: 本文使用的是1.10版本 , 可通过TradingView.version()查看当前版本. 附上开发文档地址:https://zlq4863947.gitbooks.i...** 一.修 ...

  7. python-函数基础、函数参数

    目录 函数的基础 什么是函数 为何用函数 如何调用函数 定义函数的三种形式 无参函数 有参函数 空函数 函数的返回值 什么是返回值 为什么要有返回值 函数的调用 函数参数的应用 形参和实参 位置参数 ...

  8. 解决oh-my-zsh卡顿问题

    git config --global oh-my-zsh.hide-status 1

  9. leetcode-12-stack

    409. Longest Palindrome Given a string which consists of lowercase or uppercase letters, find the le ...

  10. arm页表在linux中的融合

    参考:arm-linux内存页表创建 arm的第一级页表条目数为4096个,对于4K页第二级目录条目个数为256个,一级二级条目都是每个条目4字节. 在linux下二级分页如下:虚拟地址——> ...