课后作业-2025-10-26

**题目:**P1554 [USACO06DEC] 梦中的统计 Dream Counting B

网址: https://www.luogu.com.cn/problem/P1554

**思路:**我们从m到n枚举,对于这其中的每一个数我们都统计一下0-9这10个数出现的次数。

**知识点:**简单模拟。

代码:

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int a[10];
void cal(int x)
{
	while(x)
	{
		int t=x%10;
		a[t]++;
		x/=10;
	}
}
int main(){

    int m,n;
    cin>>m>>n;
    for(int i=m;i<=n;i++)
    {
    	cal(i);
	}
	for(int i=0;i<=9;i++)
	cout<<a[i]<<" ";
    return 0;
}

**题目:**P1200 [USACO1.1] 你的飞碟在这儿 Your Ride Is Here

网址: https://www.luogu.com.cn/problem/P1200

**思路:**我们先输入两个字符串,然后计算一下每个字符串代表的数,最后对47取模。

**知识点:**简单模拟。

代码:

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;

int main(){

    string s1,s2;
	cin>>s1>>s2;
	int v1=1,v2=1;
	for(auto it:s1)
	{
	  v1=v1*(it-'A'+1);	
	} 
	v1%=47;
	for(auto it:s2)
	{
		v2=v2*(it-'A'+1);
	}
	v2%=47;
//	cout<<"v1: "<<v1<<" "<<"v2: "<<v2<<'\n';
	if(v1==v2)
	cout<<"GO";
	else cout<<"STAY";
    return 0;
}

**题目:**P1161 开灯

网址: https://www.luogu.com.cn/problem/P1161

**思路:**对于n次操作,我们每次都用一个for循环去模拟一下。

**知识点:**简单模拟。

代码:

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;

int b[2000009];
int main(){

    int n;
    cin>>n;
    while(n--)
    {
    	double a;
    	int t;
    	cin>>a>>t;
    	for(int i=1;i<=t;i++)
    	{
    		int pos=i*a;
    		b[pos]=1-b[pos];
		}
	}
	for(int i=1;i<=2000009;i++)
	{
		if(b[i]==1)
		{
			cout<<i;
			break;
		}
	}
    return 0;
}

**题目:**P1534 不高兴的津津(升级版

网址: https://www.luogu.com.cn/problem/P1534

**思路:**今天的不高兴程度=昨天不高兴程度+今天上课总时间减去 8 。

**知识点:**简单模拟。

代码:

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;


int main(){

    int n;
    cin>>n;
    int last=0,ans=0;
    for(int i=1;i<=n;i++)
    {
    	int x,y;
    	cin>>x>>y;
    	int now=last+(x+y-8);
    	ans+=now;
    	last=now;
	}
	cout<<ans;
    return 0;
}

**题目:**P2006 赵神牛的游戏

网址: https://www.luogu.com.cn/problem/P2006

**思路:**对于这m个技能,我们先判断一下a是否等于0,因为0不能等于除数。如果a等于0且b不等于0,那么一定可以杀死boss;如果a等于0且b也等于0,那么一定不能杀死boss。否则我们先算出来技能能够释放的次数cnt,再使用次数乘以伤害,就能得到mx,如果mx大于等于n,就可以杀死boss,否则不能。

**知识点:**简单模拟。

代码:

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;

int main(){

    long long k,m,n;
    cin>>k>>m>>n;
    vector<int>vt;
    for(int i=1;i<=m;i++)
    {
    	long long a,b;
    	cin>>a>>b;
    	if(a==0)
    	{
    		if(b!=0)
    		vt.emplace_back(i);
    		continue;
		}
    	long long cnt=k/a;
    	long long mx=cnt*b;
    	if(mx>=n)
    	{
    		vt.emplace_back(i);
		}
	}
	if(vt.size()==0)
	cout<<-1<<'\n';
	else{
		for(auto it:vt)
		cout<<it<<" ";
	}
    return 0;
}
相关推荐
fab 在逃TDPIE2 分钟前
Sentaurus TCAD 仿真教程(十)
算法
天赐学c语言21 分钟前
12.19 - 买卖股票的最佳时机 && const的作用
c++·算法·leecode
菜鸟233号24 分钟前
力扣78 子集 java实现
java·数据结构·算法·leetcode
yesyesyoucan27 分钟前
在线魔方解谜站:从零入门到精通的智能魔方学习平台
学习·算法
Han.miracle29 分钟前
数据结构与算法--008四数之和 与经典子数组 / 子串问题解析
数据结构·算法
!停29 分钟前
字符函数和字符串函数
算法
AI科技星1 小时前
圆柱螺旋运动方程的一步步求导与实验数据验证
开发语言·数据结构·经验分享·线性代数·算法·数学建模
FONE_Platform1 小时前
FONE食品饮料行业全面预算解决方案:构建韧性增长
人工智能·算法·全面预算·全面预算管理系统·企业全面预算
月明长歌1 小时前
【码道初阶】【Leetcode94&144&145】二叉树的前中后序遍历(非递归版):显式调用栈的优雅实现
java·数据结构·windows·算法·leetcode·二叉树
DanyHope2 小时前
《LeetCode 49. 字母异位词分组:哈希表 + 排序 全解析》
算法·leetcode·哈希算法·散列表