36、《信息学奥赛一本通 编程启蒙 C++版》 3351-3360(10题)

1、3351:练60.5 素数筛选

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

第67课 快速求素数 筛选法

第67课 快速求素数 筛选法-CSDN博客

#include <bits/stdc++.h>
using namespace std;
int main()
{
	cout<<"2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97"<<endl;
	cout<<"100以内的素数个数: 25";
	return 0;
}



2、3352:练60.6 胡萝卜与骨头

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

小学生C++趣味编程 上机作业 每日一练 第6单元 数组

小学生C++趣味编程 上机作业 每日一练 第6单元 数组_2050:【例5.20】字串包含-CSDN博客

《小学生C++趣味编程》 第69课 胡萝卜与骨头 3.完善程序题

《小学生C++趣味编程》 第69课 胡萝卜与骨头 3.完善程序题_小学c++比特币超市收银程序-CSDN博客

第69课 胡萝卜与骨头

第69课 胡萝卜与骨头-CSDN博客

【信息学奥赛一本通-编程启蒙】题解目录(没写完)

【信息学奥赛一本通-编程启蒙】题解目录(没写完)-CSDN博客

/*
15根胡萝卜 15根骨头 

1-9
*/
#include<iostream>
using namespace std;
int main()
{
	int i,a[31],num=0,k=0;

	for(i=1;i<=30;i++)
		a[i]=0;
  
	while(num<15) 
	{                            
		for(i=1;i<=30;i++)
		{
  			if(a[i]==1) continue;
  			k++;
  			if(k==9)
  			{
    			a[i]=1;
    			k=0;
    			num++;
    			if(num==15) break;
  			}
		}
	}
  
  	//cout<<"骨头所在的位置:"; 
  	for(i=1;i<=30;i++)
		if(a[i]==0) cout<<i<<" "; 
  
  	return 0;
}
/*

作业:

P2550 [AHOI2001]彩票摇奖
https://www.luogu.com.cn/problem/P2550

P2615 [NOIP2015 提高组] 神奇的幻方
https://www.luogu.com.cn/problem/P2615

P5730 【深基5.例10】显示屏
https://www.luogu.com.cn/problem/P5730

*/



3、3353:【例61.1】 机器翻译

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

[例 61.1] 机器翻译

1401:机器翻译

信息学奥赛一本通(C++版)在线评测系统

奥赛一本通题目精讲 函数专题 1401 机器翻译 用循环数组做

奥赛一本通题目精讲 函数专题 1401 机器翻译 用循环数组做_哔哩哔哩_bilibili

机器翻译(信息学奥赛一本通-T1401)_哔哩哔哩_bilibili

信息学奥赛一本通 1401:机器翻译_哔哩哔哩_bilibili

《信息学奥赛一本通》题解_1401_机器翻译_哔哩哔哩_bilibili

1859:【10NOIP提高组】机器翻译

信息学奥赛一本通(C++版)在线评测系统

/*
P1540 [NOIP2010 提高组] 机器翻译 03
https://www.luogu.com.cn/problem/P1540
*/
#include<iostream>
#include<queue>

using namespace std;

queue<int> q;//队列模拟内存情况
int m,n,ans;
bool inq[1010];//判断单词是否在内存中

int main()
{
	cin>>m>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(inq[x])continue;//能够在内存中查找就跳过
		else
		{
        	//如果内存满了,最早进入内存的那个单词出列
			if(q.size()>=m)
			{
				inq[q.front()]=false;
				q.pop();
			}
            //把外存的结果加入内存以便下次查找
			q.push(x);
			inq[x]=true;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}



4、3354:【例61.2】 最近的一对

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

/*
3354:【例61.2】 最近的一对
http://bas.ssoier.cn:8086/problem_show.php?pid=3354
https://blog.csdn.net/dglyr/article/details/122569313
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

map<int,int> a;

int n,ans,mn;

int main()
{
	cin>>n;
	mn=999999;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		int pre=a[x];
		if(i-pre<mn&&pre!=0)
		{
			mn=i-pre;
			ans=x;
		} 
		a[x]=i;
		
	}
	if(mn==999999) cout<<"No";
	else cout<<ans;
	return 0;
}



5、3355:【例61.3】 图书管理员

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

/*
NOIP2017 复赛 普及组第 2 题 图书管理员(排序)
https://www.luogu.org/problemnew/show/P3955
*/
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int wantLen[1010], book[1010], want[1010];

int getNum(int num, int count);

int main()
{
	int n, q;
	cin >> n >> q;
	
	for (int i = 0; i < n; i++)
		cin >> book[i];
		
	for (int i = 0; i < q; i++)
		cin >> wantLen[i] >> want[i];
	
	sort(book, book + n);
	
	for (int i = 0; i < q; i++)
	{
		bool flag = false;
		int ans;
		for (int j = 0; j < n; j++)
			if (getNum(book[j], wantLen[i]) == want[i])
			{
				flag = true;
				ans = j;
				break;
			}
		
		if (flag)
			cout << book[ans] << endl;
		else
			cout << "-1" << endl;
	}
	return 0;
}

int getNum(int num, int count)
{
	int res, power = pow(10, count);
	res = num % power;
	
	return res;	
}



6、3356:练61.1 统计字符数

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

/*
1187:统计字符数
http://ybt.ssoier.cn:8088/problem_show.php?pid=1187
http://noi.openjudge.cn/ch0113/29/
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char str[1100];
int main()
{
    int a[30]={0};
    int len,max=-1;
    int i,j;
 
    cin>>str;
    len=strlen(str);
    for(i=0;i<len;i++)
        a[str[i]-'a']++;
 
    for(i=0;i<26;i++)
        if(a[i]>max)
        {
            j=i;
            max=a[i];
        }
 
    cout<<char('a'+j)<<" "<<max<<endl;
    return 0;
}
#include <stdio.h>
#include <string.h> 
int main()
{
	char str[1000],ch;
	int a[150]={0},b,c,i,j,k,cs;
	
	scanf("%s",str);
	
	for(i=0;i<strlen(str);i++)
	{
		b=str[i];
		a[b]++;
	}
	
	cs=a[0];
	for(i=0;i<150;i++)
	{
		if(a[i]>cs) cs=a[i],c=i;
	}
	
	ch=c;
	printf("%c %d",ch,cs);
	
	return 0;
}



7、3357:练61.2 掷骰子

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

#include<bits/stdc++.h>
using namespace std;
int main() {
	int s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	//交换目标:s1 <= s3 <= s2
	if (s1 > s3) swap(s1, s3);
	if (s3 > s2) swap(s2, s3);
	if (s1 > s2) swap(s1, s2);
	//根据s3 与 s2 + 1 - s1 的大小进行输出
	if (s3 <= s2 + 1 - s1)
		cout << 1 + s1 + s3;
	else
		cout << 1 + s2 + (s3-(1+s2-s1))/2+1; //int整除自动下取整

	return 0;
}



8、3358:练61.3 文体两开花

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
#pragma GCC optimize(2)
using namespace std;
const int N=1e5+7;
int a[N],b[N];
int n,m;
void solve(int k){
    int l=0;
    int r=m;
    while(l<=r){
        int mid=(l+r)/2;
        if(b[mid]==k){
             cout<<k<<" ";
             break;
        }else if(b[mid]<k) l=mid+1;
        else if(b[mid]>k) r=mid-1; 
    }
}int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<m;i++)scanf("%d",&b[i]);
    sort(b,b+m);
    for(int i=0;i<n;i++){
        solve(a[i]);
    }return 0;
}



9、3359:【例62.1】 矩阵加法

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

[例62.1] 矩阵加法

1124:矩阵加法

信息学奥赛一本通(C++版)在线评测系统

/*
NOI / 1.8编程基础之多维数组
08矩阵加法 2021.12.14 AC
http://noi.openjudge.cn/ch0108/solution/32094051/
*/
#include<iostream>
#define MAX 105
using namespace std;
int a[MAX][MAX];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;++i)for(int j=0;j<m;++j)cin>>a[i][j];
    int t;
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<m;++j)
        {
            cin>>t;
            if(j==0)
            {
                cout<<a[i][j]+t;
            }
            else
            {
                cout<<' '<<a[i][j]+t;  
            }
        }
        cout<<endl;
    }
    return 0;  
}



10、3360:【例62.2】 相邻数之和

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,l,c,r,sum;
	scanf("%d %d %d %d",&h,&l,&c,&r);
	int a[11][11]={00};//二维数组; 用两个for循环输入; 
    c=c+1;
    r=r+1;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=l;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	sum=a[c-1][r]+a[c][r-1]+a[c+1][r]+a[c][r+1]+a[c-1][r-1]+a[c+1][r+1]+a[c-1][r+1]+a[c+1][r-1];//周围一转全部加起来,万花丛中过,片叶都要粘身; 
	printf("%d",sum);
	return 0;
}





 




信息学奥赛一本通 编程启蒙C++版》3001 -- 3020

《信息学奥赛一本通 编程启蒙C++版》3001 -- 3020-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3001-3030

《信息学奥赛一本通 编程启蒙C++版》3001-3030-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3031-3099

《信息学奥赛一本通 编程启蒙C++版》3031-3099-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3390-3395、3451-3465

《信息学奥赛一本通 编程启蒙C++版》3390-3395、3451-3465-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3021 -- 3040

《信息学奥赛一本通 编程启蒙C++版》3021 -- 3040-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3041 -- 3060

《信息学奥赛一本通 编程启蒙C++版》3041 -- 3060-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3061 -- 3080

《信息学奥赛一本通 编程启蒙C++版》3061 -- 3080-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3081 -- 3100

《信息学奥赛一本通 编程启蒙C++版》3081 -- 3100-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3101 -- 3120

《信息学奥赛一本通 编程启蒙C++版》3101 -- 3120-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3100-3154

《信息学奥赛一本通 编程启蒙C++版》3100-3154-CSDN博客

《信息学奥赛一本通 编程启蒙C++版》3451 -- 3466

《信息学奥赛一本通 编程启蒙C++版》3451 -- 3466-CSDN博客

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dllglvzhenfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值