XVII Open Cup named after E.V. Pankratiev. Grand Prix of SPb D cutting potatoes
来源:互联网 发布:windows账户有什么用 编辑:程序博客网 时间:2024/05/20 00:51
一堆数,最多能分n次,求分后最大值除以最小值的 最小值
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <map>#include <iostream>using namespace std ;map<int , int> ma ;int save[200] ;struct node{ int x , y ; double value ; bool operator < ( const node & k )const { return value < k.value ; } bool operator == (const node & k ) const { if(x == k.x && y == k.y && value == k.value ) return true ; return false ; }};node ran[100000] ;int dif[500] ;int vis[500] ;/*4 35 5 3 2*/int main(){ int n , s ; while(~ scanf("%d %d" , &n , &s)){ int pos = 0 ; int dif_pos = 0 ; for(int i = 0 ; i < n ; i ++ ){ scanf("%d" , &save[i]) ; dif[dif_pos++] = save[i] ; for(int j = 1 ; j <= s ; j ++){ ran[pos].x = save[i] ; ran[pos].y = j ; ran[pos ++ ].value = save[i] * 1.0 / j ; } } sort(ran , ran + pos) ; pos = unique(ran , ran + pos) - ran ; sort(dif , dif + dif_pos) ; dif_pos = unique(dif , dif + dif_pos) - dif ; //for(int i = 0 ; i < dif_pos ; i ++ ) cout << dif[i] << endl ; //for(int i = 0 ; i < pos ; i ++ ) cout << ran[i].value << " " << ran[i].x << endl ;cout << endl ; double ans = 9999 ; int st = 0 , len = 0 ; for(int i = 0 ; i < pos ; i ++ ){ memset(vis , 0 , sizeof(vis)) ; int num = 0 ; for(int j = i ; j < pos ; j ++ ){ if(!vis[ ran[j].x ]){ num ++ ; vis[ ran[j].x ] = 1 ; } if(num == dif_pos){ //for(int i = 1 ; i <= 5 ; i ++ ) cout << vis[i] << " " ; cout << endl ; //cout << i << " " << ans << " " << ran[j].value / ran[i].value << endl ; if( ran[j].value / ran[i].value < ans ){ //cout << i << " " << j << " " << num << endl ; ans = ran[j].value / ran[i].value ; st = i ; len = j - i + 1; } break ; } } } ma.clear() ; for(int i = st ; i < st + len ; i ++ ){ if(!ma[ ran[i].x ]) ma[ ran[i].x ] = ran[i].y ; //cout << ran[i].y << " " << ran[i].x << endl ; } for(int i = 0 ; i < n-1 ; i ++ ){ printf("%d " , ma[save[i]]) ; } printf("%d\n" , ma[save[n-1]]) ; } return 0 ;}
阅读全文
0 0
- XVII Open Cup named after E.V. Pankratiev. Grand Prix of SPb D cutting potatoes
- XVII Open Cup named after E.V. Pankratiev. Eastern Grand Prix. Problem F. Buddy Numbers 贪心、数论、构造
- XVII Open Cup named after E.V. Pankratiev. Eastern Grand Prix. Problem G. Gmoogle 模拟、字符串处理、文本搜索
- Problem D. Clones and Treasures XVII Open Cup named after E.V. Pankratiev||简单模拟
- XVII Open Cup named after E.V. Pankratiev. XXI Ural Championship G glassese of solutions
- 【opencup】XVI Open Cup named after E.V. Pankratiev. GP of SPB K.Captain Tarjan【树形dp】
- Problem A. Arithmetic Derivative-XVII Open Cup named after E.V. Pankratiev||找规律&数学&DFS
- Problem L. Canonical duel XVII Open Cup named after E.V. Pankratiev||并查集
- Problem F. Matrix Game XVII Open Cup named after E.V. Pankratiev||字符串最大表示法
- XVII Open Cup named after E.V. Pankratiev Problem I. Rage Minimum Query 手写小根堆、卡时间+卡内存、或者随机化
- ICPCCamp 2016 Day 3 - Grand Prix of China(Random Arithmetic-dp)
- Deletion of open named pipes
- 2013 ACM/ICPC Asia Regional Changsha Online - I Grand Prix
- A. Two Bags of Potatoes
- Canada Cup 2016 A,B,C,D,E
- Codeforces-239A-Two Bags of Potatoes
- N o v e m b e r 7 t h W e d n e s d a y
- Log.v Log.d Log.e Log.i Log.w
- 排序算法之插入排序
- leetcode.array--40. Combination Sum II
- HDU1203 I NEED A OFFER!-概率dp
- vue 设置多个反向代理以及easy-mock的简单的使用方法
- POST和GET请求的区别
- XVII Open Cup named after E.V. Pankratiev. Grand Prix of SPb D cutting potatoes
- 未添加安全组规则设置导致通过公网IP地址不能访问ECS云服务器
- springboot使用hibernate的SessionFactory实现BaseDao
- include指令和include动作的区别
- 使用GDlib在图片上绘制文本
- 统计学名词——偏差
- 拉格朗日插值法
- 用递归实现1到100的和,1到10的阶乘
- SpnnableString 初体验