Uvalive 6441 horrible quiz greedy

Source: Internet
Author: User

Link: http://vjudge.net/problem/viewProblem.action? Id = 47588

Question: At the beginning, I had 15000 credits and N questions. For each question, I had a probability of correct CI %, and I had a probability of incorrect wi % (-ci-wi) % of the probability will select the provided answer. A maximum of m wrong answers can be provided in the provided answers, and the rest must be correct. When a wrong answer is received, the points *-1, points remain unchanged during the correct answer. Ask the M questions that you can choose to obtain the expected minimum score.

Idea: in the formula, CI and WI indicate the probability of correctness and error respectively (Ci + Wi = 1)

The probability of correct answers is different when incorrect answers and correct answers are provided, so they are recorded separately. To minimize the expected value, the optimal condition is to set the integral value as negative as possible and the expected absolute value as large as possible. If the expected value cannot be negative, the absolute value of the points must be as small as possible. You can obtain the optimal solution by deciding the question that provides the wrong answer and the question that provides the correct answer based on the ratio of the expected answers.

Code:

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#define eps 1e-8using namespace std;struct point{    int a,b;    double ac,wa;} aa[1255],zz[1255],ff[1255],cc[1255];bool cmp1(point a,point b){    return fabs(a.wa*b.ac)<fabs(b.wa*a.ac);}bool cmp2(point a,point b){    return fabs(a.wa*b.ac)>fabs(b.wa*a.ac);}int main(){    int T;    scanf("%d",&T);    for(int ii=1; ii<=T; ii++)    {        double ans=15000;        int tw=0,tt=0,tb0=0;        int tot,wrong,top1=0;        scanf("%d%d",&tot,&wrong);        for(int i=0; i<tot; i++)            scanf("%d",&aa[i].a);        for(int i=0; i<tot; i++)            scanf("%d",&aa[i].b);        printf("Case #%d: ",ii);        for(int i=0; i<tot; i++)        {            aa[i].ac=(double)((100-aa[i].b)*2-100);            aa[i].ac/=100.0;            aa[i].wa=(double)(aa[i].a*2-100);            aa[i].wa/=100.0;            if(aa[i].ac<0)            {                tw++;                ff[top1++]=aa[i];            }            else if(aa[i].wa>=0)            {                ff[top1++]=aa[i];            }            else            {                cc[tt++]=aa[i];            }            if(aa[i].ac==0)                tb0++;            if(aa[i].wa==0)                tb0++;        }        if(wrong==0)        {            for(int i=0; i<tot; i++)            {                ans*=aa[i].ac;            }            if (fabs(ans)<eps)                ans=0;            printf("%.4f\n",ans);        }        else if(tw%2==0&&tt==0)        {            if(tb0)                printf("0.000\n");            else            {                sort(ff,ff+top1,cmp1);                for(int i=0; i<wrong; i++)                {                    if(fabs(ff[i].wa)<fabs(ff[i].ac))                        ans*=fabs(ff[i].wa);                    else                    {                        ans*=fabs(ff[i].ac);                    }                }                for(int j=wrong; j<tot; j++)                    ans*=fabs(ff[j].ac);                if (fabs(ans)<eps)                    ans=0;                printf("%.4f\n",ans);            }        }        else        {            int ttw=0,ttc=0;            if(tw%2==0&&tt!=0)            {                wrong--;            ttw++;            }            sort(cc,cc+tt,cmp2);            sort(ff,ff+top1,cmp2);            while(wrong)            {                if(wrong>=2&&tt-ttw>=2)                {                    if(ttc<top1)                    {                        if(cc[ttw].wa/cc[ttw].ac*cc[ttw+1].wa/cc[ttw+1].ac>=ff[ttc].wa/ff[ttc].ac&&cc[ttw].wa/cc[ttw].ac*cc[ttw+1].wa/cc[ttw+1].ac>1)                        {                            wrong-=2;                            ttw+=2;                        }                        else if(cc[ttw].wa/cc[ttw].ac*cc[ttw+1].wa/cc[ttw+1].ac<ff[ttc].wa/ff[ttc].ac&&ff[ttc].wa/ff[ttc].ac>1)                        {                            wrong--;                            ttc++;                        }                        else break;                    }                    else                    {                        if(cc[ttw].wa/cc[ttw].ac*cc[ttw+1].wa/cc[ttw+1].ac>1)                        {                            wrong-=2;                            ttw+=2;                        }                        else break;                    }                }                else if(wrong>=1)                {                    if(ttc<top1&&ff[ttc].wa/ff[ttc].ac>1)                    {                        wrong--;                        ttc++;                    }                    else break;                }            }            for(int i=0; i<ttw; i++)                ans*=cc[i].wa;            for(int i=ttw; i<tt; i++)                ans*=cc[i].ac;            for(int i=0; i<ttc; i++)                ans*=ff[i].wa;            for(int i=ttc; i<top1; i++)                ans*=ff[i].ac;            if (fabs(ans)<eps)                ans=0;            printf("%.4f\n",ans);        }    }    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.