『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]-最小内积(第八届北京师范大学程序设计竞赛决赛)
H. 最小内积
64-bit integer IO format: %lld
Java class name: Main
Input
Output
Sample Input
5
1 2 3 4 5
1 0 1 0 1
Sample Output
6
这种拼手速的题只恨自己手速不够快,我们只需把两个相反的排序就好了,一个最大值乘以最小值和才是最小的;
SO:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1000+10;
int a[N],b[N];
int cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,i,sum;
while(~scanf("%d",&n))
{
sum=0;
for(i=0; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n);
for(i=0; i<n; i++)
scanf("%d",&b[i]);
sort(b,b+n,cmp);//逆序排序;
for(i=0; i<n; i++)
sum+=a[i]*b[i];
printf("%d\n",sum);
}
return 0;
}
『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]-最小内积(第八届北京师范大学程序设计竞赛决赛)的更多相关文章
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]--Codeforces -35D. Animals
D. Animals time limit per test 2 seconds memory limit per test 64 megabytes input input.txt output o ...
- 第十五届北京师范大学程序设计竞赛现场决赛题解&源码(A.思维,C,模拟,水,坑,E,几何,思维,K,字符串处理)
#include <bits/stdc++.h> using namespace std; int main() { int T,n,a,b; while(cin>>T) { ...
- 『PyTorch』第九弹_前馈网络简化写法
『PyTorch』第四弹_通过LeNet初识pytorch神经网络_上 『PyTorch』第四弹_通过LeNet初识pytorch神经网络_下 在前面的例子中,基本上都是将每一层的输出直接作为下一层的 ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 237C,素数打表,二分查找
C. Primes on Interval time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 236A,虽然很水,但有一个很简单的函数用起来方便
A. Boy or Girl time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]CF-236B. Easy Number Challenge
B. Easy Number Challenge time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛 C-Cities
题目描述:There are n cities in Byteland, and the ith city has a value ai. The cost of building a bidirec ...
- “浪潮杯”第九届山东省ACM大学生程序设计竞赛(重现赛)E.sequence(树状数组求逆序对(划掉))
传送门 E.sequence •题意 定义序列 p 中的 "good",只要 i 之前存在 pj < pi,那么,pi就是 "good": 求删除一个数, ...
随机推荐
- 128 Longest Consecutive Sequence 一个无序整数数组中找到最长连续序列
给定一个未排序的整数数组,找出最长连续序列的长度.例如,给出 [100, 4, 200, 1, 3, 2],这个最长的连续序列是 [1, 2, 3, 4].返回所求长度: 4.要求你的算法复杂度为 O ...
- 动手实现 Redux(三):纯函数(Pure Function)简介
我们接下来会继续优化我们的 createStore 的模式,让它使我们的应用程序获得更好的性能. 但在开始之前,我们先用一节的课程来介绍一下一个函数式编程里面非常重要的概念 —— 纯函数(Pure F ...
- ref 和 React.js 中的 DOM 操作
在 React.js 当中你基本不需要和 DOM 直接打交道.React.js 提供了一系列的 on*方法帮助我们进行事件监听,所以 React.js 当中不需要直接调用 addEventListen ...
- C#局部类型partial在定义实体类Model中的应用
以前一直用继承类的方法,原来还可以这样 //例如:定义一个Person的实体类,用户ID(PersonId),姓名(Name),性别(Sex),年龄(Age),地址(Address),联系方式(Tel ...
- .net excel 导入 导出
哎,好好的代码今天说来个实验,结果用的是office15 气死人了,网上最高office14.dll 文章转自2012年 QQ群:13615607 MR.Young protected void Bt ...
- f# mathprovider
http://mathprovider.codeplex.com/ http://mathnetnumerics.codeplex.com/releases/view/110750 http://py ...
- STM32&AT指令NBIOT模组
#include "nbiot.h" #include "string.h" #include "stdlib.h" #include &q ...
- FileZilla Server 端设置passive模式注意事项
1,需求和问题的产生 实践中需要分布在各地的各个客户端向云端服务器上传文件,因此在阿里云服务器上安装了FileZilla Server软件作为文件FTP服务端. 客户端程序采用FTP方式向服务端传输文 ...
- 【算法】最长回文子串 longest palindrome substring
对于字符串S, 要找到它最长的回文子串,能想到的最暴力方法,应该是对于每个元素i-th都向左向右对称搜索,最后用一个数组span 记录下相对应元素i-th为中心的回文子串长度. 那么问题来了: 1. ...
- dnskeygen - 针对DNS安全性所生成的公共,私有和共享的密钥
SYNOPSIS(总览) dnskeygen [- [DHR ] size ] [-F ] -[zhu ] [-a ] [-c ] [-p num ] [-s num ] -n name DESCRI ...