阅读程序 提高篇(1-8题)

1、NOIP1998 第三章 阅读程序 第3节 提高篇

/*
1、NOIP1998 第三章 阅读程序 第3节 提高篇 
*/
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int n=5;
int k;
int a[2*n+1][2*n+1];
int main( )
{
	k=1;
	for(int i=1;i<=2*n-1;++i)
		if( i<=n )
			if( i%2==1)
				for(int j=i;j>=1;--j)
				{
					a[i-j+1][j]=k;k++;
				
				}
			else  for( int j=1;j<=i;j++)
			{
				a[i-j+1][j]=k;k++;
			}
			else if( i%2==1)
				for(int j=n;j>=i-n+1;--j)
				{
					a[i-j+1][j]=k;k++;
				}
			else for(int j=i-n+1;j<=n;++j)
			{
				a[i-j+1][j]=k;k++;
			}
			
			for(int i=1;i<=n;++i)
			{
				for(int j=1;j<=n;++j)  printf("%d  ",a[i][j]);
				cout<<endl;
			}
	return 0;
}
/*
答案:
1  3  4  10  11
2  5  9  12  19
6  8  13 18  20
7  14 17 21  24
15 16  2 23  25 

1  3  4  10  11
2  5  9  12  19
6  8  13  18  20
7  14  17  21  24
15  16  22  23  25

--------------------------------
Process exited after 0.3212 seconds with return value 0
请按任意键继续. . .
*/

2.[NOIP]1998

#include <stdio.h>
#include <cstdio>
int main(){
    int i,j,s;
    int b[6];
    s=1;
    for(i=1;i<=5;i++)
        b[i]=i;
    j=1;
    while(j>0){
        j=5;
        while(j>0&&b[j]==10+j-5)
            j--;
        printf("j=%d\n",j);
        if(j>0){
            s++;
            b[j]++;
            for(i=j+1;i<=5;i++)
                b[i]=b[j]+i-j;
        }
    }
    printf("s=%d\n",s);
    return 0;
}
/*
答案:S=252 
*/

3、NOIP2000 3.1 第三章 阅读程序

//3、NOIP2000 3.1 第三章 阅读程序 
#include <stdio.h>
#include <math.h>

const int n=7,m=6;

float disp(int x1,int y1,int x2,int y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main(){
    int i,j,x0,y0,x1,y1,x2,y2;
    float d;
    int p;
    int g[n+1][m+1];
    for(i=0;i<=n;i++)
        for(j=0;j<=m;j++)
            g[i][j]=0;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    g[x1][y1]=1;
    g[x2][y2]=1;
    p=1;
    while(p){
        p=0;
        d=disp(x1,y1,x2,y2);
        x0=x1;
        y0=y1;
        for(i=4;i<=n;i++)
            for(j=0;j<=m;j++)
                if(d>disp(i,j,x2,y2)&&g[i][j]==0){
                    d=disp(i,j,x2,y2);
                    x0=i;
                    y0=j;
                }
        if(x0!=x1||y0!=y1){
            x1=x0;
            y1=y0;
            p=1;
            g[x1][y1]=1;
        }
        d=disp(x1,y1,x2,y2);
        x0=x2;
        y0=y2;
        
        for(i=0;i<=3;i++)
            for(j=0;j<=m;j++)
                if(d<disp(x1,y1,i,j)&&g[i][j]==0){
                    d=disp(x1,y1,i,j);
                    x0=i;
                    y0=j;
                }
        if(x0!=x2||y0!=y2){
            x2=x0;
            y2=y0;
            p=1;
            g[x2][y2]=1;
        }
    }
    printf("%d %d %d %d\n",x1,y1,x2,y2);
    return 0;
}
//输入7 6 0 0
//输出:
//答案:4 3 0 2 

第三章 阅读程序 提高篇 4、【NOIP2001】

https://blog.csdn.net/dllglvzhenfeng/article/details/130917545


5、2002.3.3 第三章 阅读程序

//5、2002.3.3 第三章 阅读程序 
#include <stdio.h>
#include <math.h>
int main(){
    float d1,d2,x,min;
    min=10000;
    x=3;
    while(x<15){
        d1=sqrt(9+(x-3)*(x-3));
        d2=sqrt(36+(15-x)*(15-x));
        if((d1+d2)<min)
            min=d1+d2;
        x+=0.001;
    }
    printf("%8.2f\n",min);
    return 0;
}
//答案:15.00 

6、【NOIP2002】.第三章 阅读程序

//6、2002.3.1 第三章 阅读程序
#include <stdio.h>
#include <string.h>

int main(){
    int i,n,jr,jw,jb;
    char ch1;
    char ch[22];
    scanf("%d",&n);
    scanf("%s",ch);
    jr=0;
    jw=n-1;
    jb=n-1;
    while(jr<=jw){
        if(ch[jw]=='R'){
            ch1=ch[jr];
            ch[jr]=ch[jw];
            ch[jw]=ch1;
            jr++;
        }else if(ch[jw]=='W'){
            jw--;
        }else{
            ch1=ch[jw];
            ch[jw]=ch[jb];
            ch[jb]=ch1;
            jw--;
            jb--;
        }
    }
    printf("%s\n",ch);
    return 0;
}
/* 
输入:
10
RBRBWWRBBR 
输出:
答案:
RRRRWWBBBB 
*/

 7、【NOIP2003】.第三章 阅读程序

#include <stdio.h>

int m,n;
int mark;

int test(int m,int n){
    int i,p;
    int flag;
    int ans;
    m--;
    i=0;
    flag=0;
    for(p=2*n;p>=n+1;p--){
        i=(i+m)%p;
        if(i<n){
            flag=1;
            ans=0;
            break;
        }
    }
    if(!flag)
        ans=1;
    return ans;
}

int main(){
    scanf("%d",&n);
    m=1;
    mark=0;
    do{
        if(test(m,n)==1){
            printf("%d\n",m);
            break;
        }
        m++;
    }while(mark==0);
    return 0;
}
//输入:7
//输出:
//答案:1872 

8、NOIP2003

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[6],sum,n,mx,i,j,k;
bool cover[22001];
int main(){
	cin>>a[5]>>a[4]>>a[3]>>a[2]>>a[1]>>a[0];
	if( a[5]==0 && a[3]==0 && a[1]==0){
		a[5]=a[4];
		a[4]=a[2];
		a[3]=a[0];
		a[2]=0;
		a[0]=0;
	}
	for(i=0;i<=5;i++)
		if( a[i]>10) a[i]=10+(a[i]%2);
	sum=0;
	for(i=0;i<=5;i++) sum=sum+a[i]*(6-i);
	if( sum%2!=0){
		puts("Can't be divided.")
		return 0;
	}
	sum=sum/2;
	mx=0;
	cover[0]=true;
	for(i=1;i<=sum*2;i++) cover[i]=false;
	for(i=0;i<=5;i++){
		j=0;
		while(j<=a[i]){
			for(k=mx;k>=0;k--){
				if( cover[k]) cover[k+6-i]=true;
			}
			mx=mx+6-i;
			j=j+1;
		}
	}
	if( cover[sum])
		puts("Can be divided.");
	else
		puts("Can't be divided.'");
	return 0;
}
/*
输入:4 7 9 20 56 48
输出: 
输入:1000 7 101 20 55 1
输出: 
输入:2000 5 1 1 0 0 
输出: 
答案:
Can't be divided
Can be divided
Can't be divided 
*/ 

少儿编程C++画图之GOC编程 视频和资料集

少儿编程C++画图之GOC编程 视频和资料集-CSDN博客

GoC编程(C++画图) 视频和资料集 -- 2022.07.26

GoC编程(C++画图) 视频和资料集 -- 2022.07.26_dllglvzhenfeng的博客-CSDN博客

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

dllglvzhenfeng

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

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

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

打赏作者

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

抵扣说明:

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

余额充值