码迷,mamicode.com
首页 > 其他好文 > 详细

Hdoj 5211 Mutiple 【水】

时间:2015-04-26 22:48:34      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:水题

Mutiple

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 65    Accepted Submission(s): 45


Problem Description
WLD likes playing with a sequence a[1..N]. One day he is playing with a sequence of N integers. For every index i, WLD wants to find the smallest index F(i) ( if exists ), that i<F(i)n, and aF(i) mod ai = 0. If there is no such an index F(i), we set F(i) as 0.
 

Input
There are Multiple Cases.(At MOST 10)

For each case:

The first line contains one integers N(1N10000).

The second line contains N integers a1,a2,...,aN(1ai10000),denoting the sequence WLD plays with. You can assume that all ai is distinct.
 

Output
For each case:

Print one integer.It denotes the sum of all F(i) for all 1i<n
 

Sample Input
4 1 3 2 4
 

Sample Output
6
Hint
F(1)=2 F(2)=0 F(3)=4 F(4)=0
 

Source
 
题意:求大于i(1~n-1)小于等于n的中间最小的数的和

代码:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <set>
#define LL __int64
using namespace std;
const LL Mod = 10007;
const LL M = 1e4+5;


int s[M];

int main(){
    int n;
    while(scanf("%d", &n) == 1){
        memset(s, 0, sizeof(s));
        for(int i = 1; i <= n; ++ i){
            scanf("%d", &s[i]);
        }
        int sum = 0;
        for(int i = 1; i < n; ++ i){
            int Min = 1e7;
            for(int j = i+1; j <= n; ++ j){
                if(s[j]%s[i] == 0&&Min > j){
                    Min = j;
                }
            }
            if(Min != 1e7) sum += Min; 
        }
        printf("%d\n", sum);
    }
    return 0;
}



Hdoj 5211 Mutiple 【水】

标签:水题

原文地址:http://blog.csdn.net/shengweisong/article/details/45293413

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!