Hdoj 5211 Mutiple 【水】

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(1≤N≤10000).

The second line contains N integers a1,a2,...,aN(1≤ai≤10000),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 1≤i<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

BestCoder Round #39 ($)

题意:求大于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;
}
时间: 2024-08-09 22:19:40

Hdoj 5211 Mutiple 【水】的相关文章

HDU 5211 Mutiple 水题

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5211 题解: 1.筛法: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<algorithm> 5 #include<vector> 6 using namespace std; 7 8 const int maxn=10000+10; 9 const i

HDU - 5210 - Delete &amp;&amp; 5211 - Mutiple (BestCoder Round #39)

题目传送:HDU - 5210 HDU - 5210 - Delete 思路:简单题 AC代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <vector> #include &l

hdu 5211 Mutiple 数学

Mutiple Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5211 Description wld有一个序列a[1..n], 对于每个1≤i<n, 他希望你求出一个最小的j(以后用记号F(i)表示),满足i<j≤n, 使aj为ai的倍数(即aj mod ai=0),若不存在这样的j,那么此时令F(i) = 0保证1≤n≤10000,1≤ai≤10000 对于任意

hdu.5211.Mutiple(数学推导 &amp;&amp; 在logn的时间内求一个数的所有因子)

Mutiple Accepts: 476 Submissions: 1025 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 wld有一个序列a[1..n], 对于每个1≤i<n, 他希望你求出一个最小的j(以后用记号F(i)表示),满足i<j≤n, 使aj为ai的倍数(即aj mod ai=0),若不存在这样的j,那么此时令F(i) = 0 保证1≤n≤10000,1≤

HDOJ 5317 RGCDQ 水

预处理出每个数有多少个不同的因数,因数最多不超过7 RGCDQ Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 641    Accepted Submission(s): 304 Problem Description Mr. Hdu is interested in Greatest Common Divisor (GCD). He

[hdoj]1143递归水题……可是我还没做出来……

1 #include <stdio.h> 2 #define MAX 31 3 int a[MAX]; 4 int main() { 5 int n; 6 a[0] = 1; 7 a[2] = 3; 8 for(int i = 4; i< MAX; i = i+2) 9 a[i] = 4*a[i-2] - a[i-4]; 10 while(scanf("%d",&n)==1&&n!=-1) 11 printf("%d\n",

hdu 5211 Mutiple(枚举)

题意: 思路: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int a[10000+100]; int vis[10000+100]; int main() { int n; int i,j,k; while(scanf("%d",&n)!=EOF) { int ans=0; memse

HDOJ 5387 Clock 水+模拟

Clock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 316    Accepted Submission(s): 215 Problem Description Give a time.(hh:mm:ss),you should answer the angle between any two of the minute.hou

HDOJ 5339 Untitled 水

Untitled Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 481    Accepted Submission(s): 245 Problem Description There is an integer a and n integers b1,-,bn. After selecting some numbers from b