请相信,这是一道水题,读了一周的题意

题意:

题目里面描述的那三个条件可以直接无视,关于罗马数字只要知道一个规则即可,映射如下

I 1         V 5
X 10      L 50
C 100    D 500
M 1000

如果一个字母映射的数字比后一个字母映射的数字小,当前的数字就作为负数.

MXMIII = 1000-10+1000+1+1+1=1993

输入的全是合法的罗马数字,问的问题有俩个,

在罗马数字编码中,s1+s2是否等于s3,如果相等输出Correct,要不然输出Incorrect

在阿拉伯数字编码中s1+s2是否等于s3,

罗马数字到阿拉伯数字编码规则,对于一个罗马数字中字母映射到0-9,当然,阿拉伯数字不能是前导0开头

AC:30ms

#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std; string valid = "valid";
string impossible = "impossible";
string ambiguous = "ambiguous";
string correct = "Correct";
string incorrect = "Incorrect";
int t[];
int total = ;
int vis[];
int val[];
char str[];
int length;
int endLength = ;
char eqAfterChar;
int sum1 = , sum2 = ;
void table()
{
t['I' - 'A'] = ;
t['X' - 'A'] = ;
t['C' - 'A'] = ;
t['M' - 'A'] = ;
t['V' - 'A'] = ;
t['L' - 'A'] = ;
t['D' - 'A'] = ;
} void dfs(int cur, int sum)
{
if(total == )
return;
if(cur == length)
{
if(sum1+sum2 == sum)
total++;
return;
}
char c = str[cur];
if(c == '=')
{
sum2 = sum;
sum=;
++cur;
c = str[cur];
}
else if(c == '+')
{
++cur;
c = str[cur];
sum1 = sum;
sum = ;
} if(vis[c - 'A'] == -)
{
int i = ;
if(c == eqAfterChar && endLength != )
i = ;
for(; i < ; i++)
{
if(val[i])
continue;
val[i] = ;
sum = sum * + i;
vis[c - 'A'] = i;
dfs(cur + , sum);
sum = (sum-i) / ;
vis[c - 'A'] = -;
val[i] = ;
}
}
else
{
sum = sum * + vis[c - 'A'];
dfs(cur + , sum);
sum = sum / - vis[c - 'A'];
}
} int main(const int argc, char** argv)
{
freopen("d:\\1.txt", "r", stdin);
table();
while (scanf("%s", str))
{
if(str[] == '#')
return ;
total = ;
sum1 = , sum2 = ;
memset(vis, -, sizeof(vis));
memset(val, , sizeof(val));
length = strlen(str);
int t1 = ;
int k = ; for(int i = length - ; i >= ;)
{
if(str[i] == '=' || str[i] == '+')
{
if(str[i] == '=')
eqAfterChar = str[i + ];
k = -;
--i;
continue;
}
if(i != && str[i - ] != '=' && str[i - ] != '+')
{
if(t[str[i] - 'A'] > t[str[i - ] - 'A'])
t1 = t1 + (t[str[i] - 'A'] - t[str[i - ] - 'A']) * k;
else
t1 = t1 + (t[str[i] - 'A'] + t[str[i - ] - 'A']) * k; --i;
}
else
t1 += t[str[i] - 'A'] * k;
if(k == )
endLength++;
--i;
}
if(t1 == )
cout << correct;
else
cout << incorrect;
dfs(, );
if(total == )
cout << " " << impossible << endl;
else if(total == )
cout << " " << valid << endl;
else
cout << " " << ambiguous << endl;
}
return ;
}

uva-185-暴力枚举的更多相关文章

  1. uva 11088 暴力枚举子集/状压dp

    https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...

  2. UVA 185(暴力DFS)

      Roman Numerals  The original system of writing numbers used by the early Romans was simple but cum ...

  3. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  4. UVA 10012 How Big Is It?(暴力枚举)

      How Big Is It?  Ian's going to California, and he has to pack his things, including his collection ...

  5. UVA - 11464 Even Parity 【暴力枚举】

    题意 给出一个 01 二维方阵 可以将里面的 0 改成1 但是 不能够 将 1 改成 0 然后这个方阵 会对应另外一个 方阵 另外一个方阵当中的元素 为 上 下 左 右 四个元素(如果存在)的和 要求 ...

  6. 紫书 例题 10-2 UVa 12169 (暴力枚举)

    就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...

  7. UVA 725 UVA 10976 简单枚举

    UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...

  8. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  9. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  10. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

随机推荐

  1. BZOJ4916: 神犇和蒟蒻【杜教筛】

    Description 很久很久以前,有一只神犇叫yzy; 很久很久之后,有一只蒟蒻叫lty; Input 请你读入一个整数N;1<=N<=1E9,A.B模1E9+7; Output 请你 ...

  2. BZOJ4872: [Shoi2017]分手是祝愿【概率期望DP】【思维好题】

    Description Zeit und Raum trennen dich und mich. 时空将你我分开.B 君在玩一个游戏,这个游戏由 n 个灯和 n 个开关组成,给定这 n 个灯的初始状态 ...

  3. stenciljs 学习九 使用jsx

    可以使用jsx 方便组件的开发 基本格式 主要是render 函数 class MyComponent { render() { return ( <div> <h1>Hell ...

  4. greasemonkey修改网页内指定函数

    greasemonkey replace function? 方法1:编写GM代码 alert("hello2"); var mydiv =document.getElementB ...

  5. 开发vue全局插件的4种方式

    定义全局插件的步骤 定义全局插件 pluginsUtil.js Vue.js 的插件应当有一个公开方法 install .这个方法的第一个参数是 Vue 构造器,第二个参数是一个可选的选项对象: ex ...

  6. Angular 4 路由介绍

    Angular 4 路由 1. 创建工程 ng new router --routing 2. 创建home和product组件 ng g component home ng g component ...

  7. JAVA Date类与Calendar类【转】

    Date类 在JDK1.0中,Date类是唯一的一个代表时间的类,但是由于Date类不便于实现国际化,所以从JDK1.1版本开始,推荐使用Calendar类进行时间和日期处理.这里简单介绍一下Date ...

  8. apache-cxf-2.6.3 spring集成配置

    apache-cxf-2.6.3 <?xml version="1.0" encoding="UTF-8"?><beans xmlns=&qu ...

  9. Bootstrap:目录

    ylbtech-Bootstrap:目录 1.返回顶部 1. https://getbootstrap.com/ 2. 2.返回顶部 1. http://www.runoob.com/bootstra ...

  10. CSS 标签实例一 homepage.css

    #overlayer { position: absolute; //指定一个元素(静态的,相对的,绝对或固定)的定位方法的类型. /*top: 50px;*/ left: 0; //定义了定位元素左 ...