Light OJ 1102 Problem Makes Problem 组合数

#include <iostream>

#include <string>

#include <map>

#include <vector>

#include<algorithm>

using namespace std;

typedef pair<string,int>PAIR;

bool cmp_by_value(const PAIR& p,const PAIR &a)

{

return p.second<a.second;

}

struct cmp

{

bool operator()(const string& k1, const string& k2) {

return k1.length() <= k2.length();

}

};

class Duck

{

public:

string name;

int weight;

Duck(const string &s,int w):name(s),weight(w){}

bool operator<(const Duck &d)const

{

return weight<d.weight;

}

};

void display(vector<PAIR>ducks)

{

for(vector<PAIR>::iterator iter=ducks.begin();iter!=ducks.end();iter++)

{

cout<<(*iter).first<<"  "<<(*iter).second<<endl;

}

}

int main()

{

map<string,int,cmp>m;//相同时看perate中的比较有没有等号如果有则不会被替代

m["Daffy"]=8;

m["Dewey"]=2;

m["Howard"]=7;

m["Donald"]=10;

vector<PAIR>ducks(m.begin(),m.end());

cout<<"Before sorting"<<endl;

display(ducks);

cout<<"Afer sorting"<<endl;

sort(ducks.begin(),ducks.end(),cmp_by_value);

display(ducks);

cout<<"下面是按key排序"<<endl;

sort(ducks.begin(),ducks.end());

display(ducks);

return 0;

}

Light OJ 1102 Problem Makes Problem 组合数

时间: 2024-10-21 10:19:02

Light OJ 1102 Problem Makes Problem 组合数的相关文章

(light oj 1102) Problem Makes Problem (组合数 + 乘法逆元)

题目链接:http://lightoj.com/volume_showproblem.php?problem=1102 As I am fond of making easier problems, I discovered a problem. Actually, the problem is 'how can you make n by adding k non-negative integers?' I think a small example will make things clea

Light OJ 1004 - Monkey Banana Problem dp题解

1004 - Monkey Banana Problem PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are in the world of mathematics to solve the great "Monkey Banana Problem". It states that, a monkey enters into a diamond shaped two dim

Light OJ 1102

题意: 给你一个数 N , 求分成 K 个数 (可以为 0 ) 的种数: 思路: 类似 在K个抽屉放入 N 个苹果, 不为0, 就是 在 n-1 个空隙中选 m-1个: 为 0, 就可以先在 K 个抽屉一个苹果, 之后类似了: 故答案就是 C(N+K-1, K-1): 数据大, 还控制内存... 按位乘 + 逆元 #include<bits/stdc++.h> using namespace std; typedef int LL; const int maxn = 2000000 + 131

lightoj 1102 - Problem Makes Problem

1102 - Problem Makes Problem As I am fond of making easier problems, I discovered a problem. Actually, the problem is 'how can you make n by adding k non-negative integers?' I think a small example will make things clear. Suppose n=4and k=3. There ar

light oj 1066Gathering Food (bfs 稍微有点小坑)

1066 - Gathering Food Winter is approaching! The weather is getting colder and days are becoming shorter. The animals take different measures to adjust themselves during this season. - Some of them "migrate." This means they travel to other plac

Light oj ---1058---poj---1971---Parallelogram Counting

题目链接:http://poj.org/problem?id=1971 Mean: 给定平面上的n个点,求这n个点中能构成平行四边形的个数. analyse: 由于平行四边形的两条对角线交于一点,且该点为两对角线的中点.若两线段的中点是同一个点,则这两条线段的四个顶点一定可以构成一个平行四边形! 所以可以求所有线段的中点,然后根据相同中点的个数来判断平行四边形的个数.如果一个点重复了k次,则形成的平行四边形的个数为k(k-1)/2. light oj AC #include <cstdio>

light oj 1348 树链剖分(单点更新区间求值)

http://lightoj.com/volume_showproblem.php?problem=1348 Finally the Great Magical Lamp was in Aladdin's hand. Now he wanted to return home. But he didn't want to take any help from the Genie because he thought that it might be another adventure for hi

light oj 1236 【大数分解】

给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,--em, 则结果为((1+2*e1)*(1+2*e2)--(1+2*em)+1)/2. //light oj 1236 大数分解素因子 #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <math.h> #include <ctype.h> #i

[2016-04-21][light]OJ[1234][Harmonic Number]

时间:2016-04-21 22:18:26 星期四 题目编号:[2016-04-21][light]OJ[1234][Harmonic Number] 题目大意:求∑nk=11kn∈(1,108),精确到10?8求∑k=1n1kn∈(1,108),精确到10?8 分析: 想法是打表,然后输出,但是直接打表会爆内存 解决办法,就是每隔100个来打表,节省1100的空间,然后从那个值开始计算到当前值解决办法,就是每隔100个来打表,节省1100的空间,然后从那个值开始计算到当前值 对应的整百就是n