UPC-5003 Dunglish(模拟)

5人阅读 评论(0) 收藏 举报
分类:

题目描述
A confused Dutchman trying to speak English could say “I am in the war”, even though there is no hostile activity going on. The confusion 1 here is that the English sentence “I am confused” is translated in Dutch as “Ik ben in de war”, which is phonetically (“sounding”) quite close to the first sentence. Such confusion leads to much enjoyment, but can complicate matters a bit.
Given a sentence in Dutch and a dictionary containing both correct translations as well as phonetic (incorrect) translations of individual words, find the translation of the sentence and indicate whether it is correct, or in case there is more than one find the total number of correct and incorrect translations. A sentence is correctly translated when each word of the sentence is correctly translated.
输入
The input consists of:
• One line with an integer n (1 ≤ n ≤ 20), the number of words in the Dutch sentence.
• One line with n words, the Dutch sentence s.
• One line with an integer m (1 ≤ m ≤ 10 5 ), the number of words in the dictionary.
• m lines, each with three strings d, e and c, a Dutch word, the English translation, and “correct” if this is the correct translation or “incorrect” otherwise.
A word consists of between 1 and 20 lowercase letters. Each word in s appears at least once as a Dutch word in the dictionary, no word appears more than 8 times as a Dutch word in the dictionary, and each combination of a Dutch and English word appears at most once.
输出
In case there is only a single translation of s, output one line with the translation followed by one line with “correct” or “incorrect”. In case there is more than one translation, output one line with the number of possible correct translations followed by “correct”, and one line with the number of possible incorrect translations followed by “incorrect”.
样例输入
7
als mollen mollen mollen mollen mollen mollen
4
als when correct
mollen moles correct
mollen destroy correct
mollen mills incorrect
样例输出
64 correct
665 incorrect

题意,给出一具丹麦语,给出字典,并给出字典的每个翻译是否正确,计算有多少总组合排列的意思是对的,有多少是错的。若只有一组排列,输出这组排列,并输出他是对是错。注意计数可能爆int

水题,模拟就好。

#include<bits/stdc++.h>///组合,最后样例没给出所有题意有坑点,只有一种排列时输出那种排列并判断
#define LL long long
using namespace std;
map<string,int>mp;
map<string,string>link;
LL poww(LL a,LL b)
{
    LL ans=1;
    while(b)
    {
        if(b&1)ans*=a;
        a*=a;
        b>>=1;
    }
    return ans;
}
int main()
{
    int n,num[30],cnt[30],worry[30],sum;
    string str[30];
    while(scanf("%d",&n)!=EOF)
    {
        sum=0;
        mp.clear();
        link.clear();
        memset(num,0,sizeof(num));
        memset(cnt,0,sizeof(cnt));
        memset(worry,0,sizeof(worry));
        for(int i=0; i<n; i++)
        {
            cin>>str[i];
            if(mp[str[i]]==0) mp[str[i]]=++sum;
            num[mp[str[i]]]++;
        }
        int m;
        string l,r,ju;
        scanf("%d",&m);
        for(int i=0; i<m; i++)
        {
            cin>>l>>r>>ju;
            if(mp[l])link[l]=r;
            if(ju[0]=='c'&&mp[l])cnt[mp[l]]++;
            else if(ju[0]=='i'&&mp[l])worry[mp[l]]++;
        }
        LL ans=1,right=1;
        for(int i=1; i<=sum; i++)
        {
            right*=poww((LL)cnt[i],(LL)num[i]);
            ans*=poww((LL)cnt[i]+(LL)worry[i],(LL)num[i]);
        }
        if(ans==1)
        {
            for(int i=0;i<n;i++)
            {
                cout<<link[str[i]];
                if(i==n-1)printf("\n");
                else printf(" ");
            }
            printf("%s\n",right==1?"correct":"incorrect");
        }
        else
        {
            ans=ans-right;
            printf("%lld correct\n%lld incorrect\n",right,ans);
        }
    }
}
查看评论

UPC 中国石油大学OJ AC百题留念。

    不知不觉,从九月份入校,十月份开始接触ACM,到如今已然七个月份,二百余天。在这些时日里,有新生赛拿第一受到奖励的甜,也有在面对其他高校的学员然后被吊打的苦闷,有AC的喜悦,也有无尽WA,TL...
  • sudu6666
  • sudu6666
  • 2018-03-29 00:49:14
  • 31

模拟汽车转向灯控制程序

  • 2011年06月15日 10:40
  • 1KB
  • 下载

模拟jsonp跨域方法

jsonp 跨域方法详解什么事跨域浏览器的同源策略,出于防范跨站脚本的攻击,禁止客户端脚本(如 JavaScript)对不同域的服务进行跨站调用。- 协议名protocol - 主机host - 端口...
  • omlys
  • omlys
  • 2016-10-23 13:07:44
  • 762

模拟炒股源码 集合(6个)

  • 2016年02月03日 15:14
  • 8.13MB
  • 下载

模拟地与数字地详解

简单来说,数字地是数字电路部分的公共基准端,即数字电压信号的基准端;模拟地是模拟电路部分的公共基准端,模拟信号的电压基准端(零电位点)。 一、分为数字地和模拟地的原因        由于数字信号一般为...
  • kevinhg
  • kevinhg
  • 2013-09-27 09:49:28
  • 39337

采用if-else-if语句实现的模拟汽车转向灯控制程序

  • 2011年06月15日 10:41
  • 1KB
  • 下载

数据结构与算法之模拟算法 C++实现

模拟算法:模拟整个过程,通过改变数学中模型的各种参数,进而观察变更这些参数所引起过程状态的变化。...
  • guugle2010
  • guugle2010
  • 2014-11-15 20:21:21
  • 1614

采用if语句实现的模拟汽车转向灯控制程序

  • 2011年06月15日 10:40
  • 1009B
  • 下载

手动模拟Session机制的原理

概要的说,.NET内置的Session其实是借助于Cookie机制实现的。下面先解释为什么这么说,然后通过对比一个.NET内置的Session实例和一个手动模拟的Session机制(会借助于Cooki...
  • wang379275614
  • wang379275614
  • 2014-01-26 21:35:49
  • 5702

简单模拟支付宝转账系统

此案例为加深对数据库操作时,对事务的理解,当转钱过程中由于某些原因发生错误时,会出现A的钱变少而B 无改变的状况,或是其他不正确的情况,注意正确的是A转给B10元,A-10   B+10,这个时候就...
  • Bazingaea
  • Bazingaea
  • 2016-10-01 11:39:13
  • 1883
    个人资料
    持之以恒
    等级:
    访问量: 9172
    积分: 1412
    排名: 3万+
    最新评论