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编程 视频和资料集
GoC编程(C++画图) 视频和资料集 -- 2022.07.26