Hdoj—1789

//大意理解 先排序 最早交的里面选最大值 扫描完了加没写的 排序后 应该是早交的和扣分多的在前 用结构体吧
/*#include<stdio.h>
#include<stdio.h>
int cmp(void const* a,void const*b)
{
if(*(st*)a->t==*(st*)b->t)
return *(st*)b->kou-*(st*)b->kou;
else
return *(st*)a->t-*(st*)b->t;
}
typedef struct
{
int vis;
int t;
int kou;

}st s[10000];
int main()
{
return 0;
}*/ //理解完全错误啊这样选择完全得不到解

题意就是最大的最迟做 做不了就被扣分。。 AC代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct st
{
    int time;;
    int score;

}a[1001];
int cam(const void *x,const void *y)
{
    struct st p = *((struct st *)x);
    struct st q = *((struct st *)y);

      return q.score-p.score;

}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n, vis[1001];

        scanf("%d",&n);
        int i;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i].time);
        }
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i].score);
        }
        for(i=1;i<=n;i++)
        //printf("%d %d\n",a[i].time,a[i].score);
        qsort(&a[1],n,sizeof(a[1]),cam);
        int count = 0;
        int day=0;
        int j;
        memset(vis,0,sizeof(vis));
        for(i=1;i<=n;i++)
        {

            for(j=a[i].time;j>=1;j--)
            {

                if(!vis[j])
                {

                    vis[j]=1;
                    break;
                }
            }
            if(j<=0)
            count+=a[i].score;
        }
        printf("%d\n",count);

    }
    return 0;
}

感觉和网上搜的如出一辙。。。

#include<stdio.h>
#include<stdlib.h>
typedef struct
{
    //int vis;
    int t;
    int kou;

}st;
st s[10000];
int vis[100000];
int cmp(void const* a,void const*b)
{
    return ((st*)b)->kou-((st*)a)->kou;
}

int main()
{
    int max_t,i,ci,c;
    scanf("%d",&ci);
    while(ci--){
        int sum=0,j;
        scanf("%d",&c);
        max_t=-1;
        for(i=0;i<c;i++)
        {
            scanf("%d",&s[i].t);
            max_t=max_t>s[i].t?max_t:s[i].t;
        }
        for(i=1;i<=max_t;i++)vis[i]=0;
        for(i=0;i<c;i++)
        {
            scanf("%d",&s[i].kou);
        }
        qsort(s,c,sizeof(s[0]),cmp);
        for(i=0;i<c;i++)
        {
            for(j=s[i].t;j>0;j--)
            {
                if(!vis[j])
                {
                    vis[j]=!vis[j];
                    break;
                }
            }
            if(j==0)
            {
                sum+=s[i].kou;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
时间: 2024-12-15 02:49:38

Hdoj—1789的相关文章

hdoj 1789 Doing Homework again 【贪心】

贪心策略:先按分数从大到小排序,分数一样,再按时间从小到大排序 分最高的越靠近期限完成,越好 话不多说直接看代码 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1789 代码: #include<cstdio> #include<cstring> #include<algorithm> using std::sort; typedef struct{ int sco, time; }str; str s[1005]; bo

hdoj 1789 Doing Homework again

Doing Homework again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8638    Accepted Submission(s): 5090 Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ha

HDOJ 题目1789 Revenge of Fibonacci(大数, 字典树)

Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 204800/204800 K (Java/Others) Total Submission(s): 2405    Accepted Submission(s): 609 Problem Description The well-known Fibonacci sequence is defined as following: Here w

【HDOJ】4328 Cut the cake

将原问题转化为求完全由1组成的最大子矩阵.挺经典的通过dp将n^3转化为n^2. 1 /* 4328 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #include <stack> 9 #include <vector>

POJ Xiangqi 4001 &amp;&amp; HDOJ 4121 Xiangqi

题目链接(POJ):http://poj.org/problem?id=4001 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=4121 Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1108   Accepted: 299 Description Xiangqi is one of the most popular two-player boa

【HDOJ】4956 Poor Hanamichi

基本数学题一道,看错位数,当成大数减做了,而且还把方向看反了.所求为最接近l的值. 1 #include <cstdio> 2 3 int f(__int64 x) { 4 int i, sum; 5 6 i = sum = 0; 7 while (x) { 8 if (i & 1) 9 sum -= x%10; 10 else 11 sum += x%10; 12 ++i; 13 x/=10; 14 } 15 return sum; 16 } 17 18 int main() { 1

HDOJ 4901 The Romantic Hero

DP....扫两遍组合起来 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 547    Accepted Submission(s): 217 Problem Description There is an old country and the king fell in love with a

【HDOJ】1099 Lottery

题意超难懂,实则一道概率论的题目.求P(n).P(n) = n*(1+1/2+1/3+1/4+...+1/n).结果如果可以除尽则表示为整数,否则表示为假分数. 1 #include <cstdio> 2 #include <cstring> 3 4 #define MAXN 25 5 6 __int64 buf[MAXN]; 7 8 __int64 gcd(__int64 a, __int64 b) { 9 if (b == 0) return a; 10 else return

【HDOJ】2844 Coins

完全背包. 1 #include <stdio.h> 2 #include <string.h> 3 4 int a[105], c[105]; 5 int n, m; 6 int dp[100005]; 7 8 int mymax(int a, int b) { 9 return a>b ? a:b; 10 } 11 12 void CompletePack(int c) { 13 int i; 14 15 for (i=c; i<=m; ++i) 16 dp[i]