一些签到题

[NOIP2012 普及组] 质因数分解 - 洛谷

唯一分解定理:一个数能且只能分解为一组质数的乘积。

因为题目给定的n一定能被拆成两个质数的乘积,因此遍历一遍2-n,只要找到的约数就是这俩质数之一。

#include<bits/stdc++.h>
using ll=long long;
using PII=std::pair<double,double>;

#define fir first
#define sec second

const int N=2e5+10;
void solve()
{
	int n;
	std::cin>>n;
	
	for(int i=2;i<=n;i++)
	{
		if(n%i==0)
        {
          std::cout<<n/i;
          break;
        }
	}
	
}
signed main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	
	int t=1;
	//std::cin>>t;;
	while(t--)
	{
		solve();
	} 
	return 0;
}

信友队-猴子吃桃

比如一开始有n个桃子,吃了n/2+1,最后剩下n/2-1个桃子。

突破点在于这题最后只剩下一个桃子,所以倒数第二天一定是4个桃子,倒数第三天一定是10个桃子,因此这就是个递推的数列。

#include<bits/stdc++.h>
using ll=long long;
using PII=std::pair<double,double>;

#define fir first
#define sec second

const int N=2e5+10;

int f[N];
void solve()
{
	int n;
	std::cin>>n;
	
	ll sum=0;
	int now=1;
	for(int i=1;i<n;i++)
	{
		//sum+=now;
		now=(now+1)*2;
	}
	std::cout<<now;
}
signed main()
{
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	
	int t=1;
	//std::cin>>t;;
	while(t--)
	{
		solve();
	} 
	return 0;
}

信友队-回型矩阵

#include<stdio.h>
 
int a[100][100];
int n;
void Visit(int n)
{
    int p=1,q=n;
    int count=0;
 
    while(count<n*n)
    {
        for(int i=p;i<=q;i++)//从上面开始赋值
            a[p][i]=++count;
 
        for(int i=p+1;i<=q;i++)//从右边开始赋值
            a[i][q]=++count;
 
        for(int i=q-1;i>=p;i--)//从下面开始赋值
            a[q][i]=++count;
 
        for(int i=q-1;i>=p+1;i--)
            a[i][p]=++count;
            p++;
            q--;
    }
}
void Print(int n)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            printf("%d ",a[i][j]);
        
        printf("\n");
    }
}
int main()
{
    scanf("%d",&n);
    Visit(n);
    Print(n);
    return 0;
}

相关推荐

  1. (C)一些9

    2024-07-20 02:54:03       43 阅读
  2. (C)一些11

    2024-07-20 02:54:03       49 阅读
  3. (C)一些10

    2024-07-20 02:54:03       47 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-20 02:54:03       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-20 02:54:03       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-20 02:54:03       45 阅读
  4. Python语言-面向对象

    2024-07-20 02:54:03       55 阅读

热门阅读

  1. LLM推理需要占用多少显存

    2024-07-20 02:54:03       16 阅读
  2. 应届硕士职业生涯规划

    2024-07-20 02:54:03       16 阅读
  3. 2024 Linux 运维面试题分享-1

    2024-07-20 02:54:03       15 阅读
  4. 大模型日报 2024-07-19

    2024-07-20 02:54:03       17 阅读
  5. Vant组件库的按需导入和导出

    2024-07-20 02:54:03       18 阅读
  6. UDP checksum calculation

    2024-07-20 02:54:03       20 阅读
  7. 设计模式总结

    2024-07-20 02:54:03       19 阅读