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
原创粉丝点击