topcoder 673
DiV1
300:给一组士兵再给一组战马都有权值。
安排战马的顺序的方案数,是第一个士兵和其战马的权值乘积最大。
做法:随便暴力就好。
枚举战马和第一个士兵匹配。其他士兵按权值从大到小排序,战马权值按从小到大排序。1.
举个例子:士兵,A,B,C,D,E
战马,a,b,c,d,e
第一个士兵和其战马的乘积是:tmp
A 可以A*c<tmp;
B 可以 B*d<tmp;
B 与战马的乘积小于tmp,其战马的权值一定大于等于c,因为 1.
所以答案就是ans = (c-第几个士兵+1)*(d-第几个士兵+1)...
#include<bits/stdc++.h> using namespace std;
typedef long long ll; #define mod 1000000007 int a[],b[]; class BearCavalry {
public:
int countAssignments(vector <int> warriors, vector <int> horses) {
int n=warriors.size();
for (int i=;i<n;i++)
a[i]=warriors[i];
sort(a+,a+n);
reverse(a+,a+n); ll ans=; for (int i=;i<n;i++)
{
int t=;
for (int j=;j<n;j++)
if (i!=j) b[t++]=horses[j];
sort(b,b+t); int tmp=a[]*horses[i]; ll num=;
for (int i=;i<n;i++){
int x=-;
for (int j=;j<t;j++)
{
if (a[i]*b[j]<tmp)
{
x=j;
}
else break;
}
//if (x==-1&&i>1) x=0;
int xx=x+-(i-);
if (xx<) xx=;
num=num*xx%mod;
}
ans=(ans+num)%mod;
// cout<<num<<endl; }
return ans;
}
}; int main()
{
BearCavalry p;
int n;
cin>>n;
vector<int>aa,ba;
for (int i=;i<=n;i++)
{
int x;
cin>>x;
aa.push_back(x);
}
for (int i=;i<=n;i++)
{
int x;
cin>>x;
ba.push_back(x);
} cout<<p.countAssignments(aa,ba);
return ;
}
topcoder 673的更多相关文章
- Topcoder Srm 673 Div2 1000 BearPermutations2
\(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...
- TopCoder kawigiEdit插件配置
kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...
- 记第一次TopCoder, 练习SRM 583 div2 250
今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...
- TopCoder比赛总结表
TopCoder 250 500 ...
- Topcoder几例C++字符串应用
本文写于9月初,是利用Topcoder准备应聘时的机试环节临时补习的C++的一部分内容.签约之后,没有再进行练习,此文暂告一段落. 换句话说,就是本文太监了,一直做草稿看着别扭,删掉又觉得可惜,索性发 ...
- UVa 673 Parentheses Balance -SilverN
You are given a string consisting of parentheses () and []. A string of this type is said to be corr ...
- TopCoder
在TopCoder下载好luncher,网址:https://www.topcoder.com/community/competitive%20programming/ 选择launch web ar ...
- TopCoder SRM 596 DIV 1 250
body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...
- UVa 673 Parentheses Balance
一个匹配左右括号的问题 /*UVa 673 Parentheses Balance*/ #include<iostream> #include<algorithm> #incl ...
随机推荐
- 2014年互联网IT待遇【转载】
2014年互联网IT待遇[转载] 一.民企 1.百度 13k*14.6,special 14~17k*14.6 开发类 13K*14.6 (2014) 测试类.前端类 12K*14.6 ( ...
- Javascript -- Math.round()、Math.ceil()、Math.floor()、parseInt去小数取整总结
一.Math.round() 作用:四舍五入返回整数.(返回参数+0.5后,向下取整) Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round( ...
- asp.net中c# TextBox.MaxLength例子
TextBox.MaxLength 属性获取或设置文本框中最多允许的字符数文本框中最多允许的字符数.默认值为 0,表示未设置该属性.使用 MaxLength 属性限定可以在 TextBox 控件中输入 ...
- Type 'System.IO.FileStream' with data contract name 'FileStream:http://schemas.datacontract.org/2004/07/System.IO' is not expected.
今天在WCF项目里使用DataContract序列化接口参数的时候,报了这个错,错误详细信息如下: System.ServiceModel.CommunicationException: There ...
- 【学习笔记】【C语言】指向函数的指针
每个函数都有自己的内存地址,指针保存了函数的地址后就能指向函数了. #include <stdio.h> double haha(double d, char *s, int a) { } ...
- 细说SQL 连接
连接条件可在FROM或WHERE子句中指定,建议在FROM子句中指定连接条件.WHERE和HAVING子句 也可以包含搜索条件,以进一步筛选连接条件所选的行. ...
- How Do I Declare A Block in Objective-C?
As a local variable: returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...}; As a p ...
- OC7_代理的基本概念
// // Cat.h // OC7_代理的基本概念 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxue ...
- eclipse优化(部分)
1. 增强Eclipse(MyEclipse)输入代码提示功能 一般设置: (1). 打开Eclipse,选择打开" Window -- Preferences". (2). 在目 ...
- Bring up a website by wordpress
WORDPRESS WordPress is web software you can use to create a beautiful website or blog, which is both ...