Bruteforce
来源:互联网 发布:杭州行知幼儿园 编辑:程序博客网 时间:2024/06/05 20:14
Problem Description
Given three arraies A[],B[],C[], each contains N non-negative integers.You are asked to maxmize the vale:V=max(A[i]+B[j]+C[k]), where 0<i,j,k<=N and i!=j and j!=k and i!=k.
Input
Each case contains 4 lines,
the first line contains an integer N( 3<=N<=10000 ) ,
the second line contains N integers representing array A[],
the third line contains N integers representing array B[],
the fourth line contains N integers representing array C[].
the first line contains an integer N( 3<=N<=10000 ) ,
the second line contains N integers representing array A[],
the third line contains N integers representing array B[],
the fourth line contains N integers representing array C[].
Output
Each case contains a number seperately: the answer V.
Sample Input
31 2 33 2 13 2 1
Sample Output
8
由于前一阵子在帮着做电子综合设计的破东西,竟然把我挚爱的ACM给遗忘了一阵子,真是该死啊!!回到杭电开始做题,今天本打算K掉DIY里面的一个比赛的,居然花了一个小时的时候做了一道水题,真是不应该啊,不过也巩固了DFS的用法,嘿嘿,几天不做手变得好生疏啊。。。。
# include<stdio.h># include<string.h>int a[10001],b[10002],c[10003];intid1[10001],id2[10002],id3[10003];int max(int i,int j,int k){i=i>j?i:j;k=k>i?k:i;return k;}int max2(int i,int j){return i>j?i:j;}int cmp1(const void *d,const void *e){return a[*((int*)e)]-a[*((int*)d)];}int cmp2(const void *d,const void *e){return b[*((int*)e)]-b[*((int*)d)];}int cmp3(const void *d,const void *e){return c[*((int*)e)]-c[*((int*)d)];}void print(int *a,int n){int i;for(i=0;i<n;i++)printf("%d ",a[i]);printf("\n");}int work(int i,int j,int k){if(id1[i]!=id2[j]&&id1[i]!=id3[k]&&id2[j]!=id3[k])return a[id1[i]]+b[id2[j]]+c[id3[k]];if(id1[i]==id2[j])return max2(work(i+1,j,k),work(i,j+1,k));if(id1[i]==id3[k])return max2(work(i+1,j,k),work(i,j,k+1));if(id3[k]==id2[j])return max2(work(i,j+1,k),work(i,j,k+1));}void main(){int n,i,j;while(scanf("%d",&n)!=EOF){for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)scanf("%d",&b[i]);for(i=0;i<n;i++){scanf("%d",&c[i]);id1[i]=i,id2[i]=i,id3[i]=i;}qsort(id1,n,sizeof(id1[0]),cmp1);qsort(id2,n,sizeof(id2[0]),cmp2);qsort(id3,n,sizeof(id3[0]),cmp3);printf("%d\n",work(0,0,0));}}
- Bruteforce
- Dirb Dir Bruteforce
- Codeforces 513C Second price auction (bruteforce)
- 使用BruteForce方法构建交通网络拓扑关系
- Hacking WPA 2 Key using Reaver (WPS Bruteforce)
- Linux登录验证机制、SSH Bruteforce Login学习
- How to Bruteforce WPA/WPA2 with Pyrit (Tutorial)
- Hacking WPA 2 Key - Evil Twin (No Bruteforce)
- 串的操作(一) BruteForce (BF)算法 朴素的模式匹配
- codeforces 851 D. Arpa and a list of numbers(前缀和+bruteforce)
- 在android 上,使用Opencv3.0实现图像无缝拼接,Fast查找特征点,BruteForce进行匹配
- C#学习
- #pragma pack 介绍
- 关系数据库数据模型设计及设计工具PowerDesigner中实现CDM(概念模型)设计并转化为PDM(物理模型)
- OpenVPN的性能极限
- CEGUI配置 快速上手(VS2008)
- Bruteforce
- 读写Excel2003文档
- 杂记之C语言之关键字const
- 创建带有表格的PPT
- Qt 之路 (02)—你好,世界!
- 如何在AODV(NS-2)中实现混杂模式并且实现邻居监测功能
- 如何查看class文件对应的JDK版本
- ios UIWindow & UIWindowLevel
- 入门视频采集与处理(显示YUV数据)