信息与未来2021

信息与未来2021(:

题单

1.幸运数字

传送门

题目描述

如果⼀个正整数 n n n 在五进制、七进制、九进制的表⽰下都没有数字 0 0 0,我们就称 n n n 是幸运数字。例如:

  • ( 987 ) 10 = ( 12422 ) 5 = ( 2610 ) 7 = ( 1316 ) 9 (987)_{10}=(12422)_5=(2610)_7=(1316)_9 (987)10=(12422)5=(2610)7=(1316)9,因此 n = 987 n=987 n=987 不是幸运数字。

  • ( 988 ) 10 = ( 12423 ) 5 = ( 2611 ) 7 = ( 1317 ) 9 (988)_{10}=(12423)_5=(2611)_7=(1317)_9 (988)10=(12423)5=(2611)7=(1317)9,因此 n = 988 n=988 n=988 是幸运数字。

写程序求出 a , a + 1 , a + 2 , ⋯   , b a,a+1,a+2,\cdots,b a,a+1,a+2,,b 之间⼀共有多少个幸运数字。

输入格式

输入一行两个正整数 a a a b b b

输出格式

输出一行,表示 a , a + 1 , a + 2 , ⋯   , b a,a+1,a+2,\cdots,b a,a+1,a+2,,b 中幸运数字的个数。

分析:

在五进制、七进制、九进制的表示下都没有数字 0 ,可以用短除法不断模x(5,7,9)
如果发现0就返回false

复杂度: O ( b − a ) O(b-a) O(ba)
代码实现:
#include <bits/stdc++.h>
using namespace std;
bool check(int n , int x) {
    while(n) {
        if ( n % x == 0) return false;
        n /= x;
    }
    return true;
}
int a,b,ans;
int main() {
    cin >> a >> b;
    for(int i =a ; i <= b ;i++) {//a循环到b
        if(check(i,5) && check(i,7) && check(i,9)) ans++;
    }
    cout << ans << endl;
    return 0;
}

2.摩尔斯电码

传送门

题目背景

早期的电报机只能表达两种状态:电路导通和电路断开。电路导通时喇叭可以发声;断开时则不发声。如何⽤这样的机器来传递⼈类能理解的信号呢?聪明的你⼀定想到了——时间的长短可以表达不同的含义(例如长代表 1 \tt{1} 1、短代表 0 \tt{0} 0),然后再把 01 \tt{01} 01 的⼆进制序列对应到字符就可以啦。

题目描述

摩尔斯电码就是这样⼀种早期的数字通信协议,它通过喇叭发声长短来表示不同的英文字母:

  1. 点(半角点号 .),喇叭响 1 1 1 单位时间,读作“滴”( d i t \tt dit dit);
  2. 划(半角减号 -),喇叭响 3 3 3 单位时间,读作“嗒”( d a h \tt dah dah);
  3. 字符/单词间的停顿,字符停顿 3 3 3 单位时间,单词停顿 7 7 7 单位时间。

下图列出了摩尔斯电码和英文字母之间的对应:

例如,大家可以试试把 ... --- ... 对照上面的表格翻译成英⽂(空格代表字符的分割)。没错,这就是著名的 “ S O S \tt SOS SOS” 紧急求救信号。现在,你需要写⼀个程序把收到的摩尔斯电码翻译回英文字符。

输入格式

输⼊数据的第一行是⼀个整数 n n n,代表共有 n n n 个需要解码的英文字母。

输⼊数据的第二行包含 n n n 个摩尔斯电码点/划组成的字符串(字符串之间用一个空格隔开),每个字符串仅包含若干半角减号 - 和半角点号 .,且保证能翻译为 26 26 26 个英文字母中的⼀个。

输出格式

输出一行,为摩尔斯电码解码后得到的字符串。

分析:

不得不说这题是真的麻烦啊
先定义一个函数进行decode解码(耗了我30分钟去调)
对于每个摩尔斯电码,将它解码后拼接在sub上

复杂度: O ( n ) O(n) O(n)
代码实现:
#include <bits/stdc++.h>
using namespace std;
string s,sub="";
int n;
char decode(string s){
    if(s==".-")return 'A';
    if(s=="-...")return 'B';
    if(s=="-.-.")return 'C';
    if(s=="-..")return 'D';
    if(s==".")return 'E';
    if(s=="..-.")return 'F';
    if(s=="--.")return 'G';
    if(s=="....")return 'H';
    if(s=="..")return 'I';
    if(s==".---")return 'J';
    if(s=="-.-")return 'K';
    if(s==".-..")return 'L';
    if(s=="--")return 'M';
    if(s=="-.")return 'N';
    if(s=="---")return 'O';
    if(s==".--.")return 'P';
    if(s=="--.-")return 'Q';
    if(s==".-.")return 'R';
    if(s=="...")return 'S';
    if(s=="-")return 'T';
    if(s=="..-")return 'U';
    if(s=="...-")return 'V';
    if(s==".--")return 'W';
    if(s=="-..-")return 'X';
    if(s=="-.--")return 'Y';
    if(s=="--..")return 'Z';
}
char ch;
int main(){
    cin>>n;
    while(n--){
        cin>>s;
        ch=decode(s);
        sub+=ch;
    }
    cout<<sub<<endl;
    return 0;
}

3.括号序列

传送门

题目描述

你得到了一个仅包含左圆括号 ( 和右圆括号 ) 的字符串,但其中的括号并不配对。为了使这个字符串变得更好看,你希望在字符串中插⼊尽可能少的圆括号(可以在任意位置插⼊任意数量的括号,但已有的括号不能改变),使修改后的字符串括号配对。

输入格式

输⼊一行一个字符串,为括号未全部配对的圆括号序列。

输出格式

输出一行,为插⼊圆括号后配对的字符串。如有多种长度最短的方案,输出任意⼀个即可。

分析:

枚举s1的每一个括号,如果是 ( 就将其入栈并输出;
如果是 ) 就判断栈顶是否是 ( 是的话删掉那个 (
不是的话 输出时要补一个(

复杂度: O ( s 1. s i z e ( ) ) O(s1.size()) O(s1.size())
代码实现:
#include <bits/stdc++.h>
using namespace std;
string s1;
stack<char> st;
int cnt;
int main()
{
	cin >> s1;
	for(int i = 0; i < s1.length(); i++){
		if(s1[i] == '(')
		{
			cout << '(';
			st.push('(');
		}
		if(s1[i] == ')'){
			if(!st.empty()&&st.top() == '('){
				cout << ')';
				st.pop();//弹出栈顶
			}
			else
			    cout << "()";			
		}
	}
	while(!st.empty())cout << ")", st.pop();//将栈中剩下的 ( 都匹配上 )
	return 0;
} 

4.文本分类

传送门

题目背景

“分类” 是人工智能中很重要的一项任务,例如区分视频中的⼀帧图像是否存在异常事件、辨别图片中是否有待检索的目标、划分音频中词语的分界位置等。

题目描述

虽然属于“人工智能”的范畴,但分类问题也可以简单理解成是一个计算机函数 f f f,它输⼊一系列数据(例如代表图片颜色的二维数组、代表⽂本的字符串等), f ( x ) f(x) f(x) 返回 0 0 0 1 1 1,其中 1 1 1 则代表 x x x 具有某种特征,属于这⼀分类。

今天,⼤家要挑战一项文本的分类任务:识别一个单词序列是由英文书写的,还是由汉语拼音书写的。以下分别是两段文字,是用汉语拼音和英文书写的,你能正确地分类吗?

  1. While a number of definitions of artificial intelligence (AI) have surfaced over the last few decades, John McCarthy offers the following definition in this 2004 paper, " It is the science and engineering of making intelligent machines, especially intelligent computer programs. It is related to the similar task of using computers to understand human intelligence, but AI does not have to confine itself to methods that are biologically observable."

  2. Ren gong zhi neng shi yan jiu、kai fa yong yu mo ni、yan shen he kuo zhan ren.de zhi neng de li lun、fang fa ji ying yong xi tong de yi men xin de ji shu ke xue.

输入格式

输⼊数据的第一行是你需要分类文本的任务数量 T T T

接下来 T T T 行,每⾏描述了⼀个文本分类任务,首先是整数 n n n 表示单词的个数,接下来 n n n 个空格分隔的、仅由小写字母 a ∼ z \tt{a}\sim \tt{z} az 组成的字符串代表了⼀段待分类的文本。输⼊保证每个单词(对中⽂来说是每个字)之间都有一个空格。

输出格式

为每个分类任务输出一行,如果待分类的文本是拼音书写的,输出 Pinyin,如是英文书写的,输出 English(注意 PinyinEnglish 的大小写)。

样例 #1
样例输入 #1
2
14 zhe ge ti mu qi shi bi ni xiang xiang de yao jian dan
6 this problem has a simple solution
样例输出 #1
Pinyin
English
分析:

如果有词末尾是s或t,则是英文骗分

复杂度: O ( n ∗ t ) O(n*t) O(nt)
代码实现:
#include <bits/stdc++.h>
using namespace std;
string s[10086];
int main()
{
    int t, n;
    cin >> t;
    while (t--)
    {
        int f = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            string s;
            cin >> s;
            char x = *s.rbegin();
            if(x == 's' || x == 't')
                f = 1;
        }
        if (f)
            cout << "English\n";
        else
            cout << "Pinyin\n";
    }
    return 0;
}
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值