1、【NOIP1998】第三章 阅读程序 第2节 普及篇(B)
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
using namespace std;
int i,j;
int i_1,j_1;
int k,s,t,s1,l,swapp;
const int n=4;
char temp,a[n*2+1];
int main( )
{
for(int i=1;i<=2*n;++i) a[i]=getchar();
s=0;t=0;
for(int i=1;i<=n*2;++i)
if( a[i]=='1') s++;
else if( a[i]=='0') t++;
if( s!=n || t!=n ) printf("error");
else
{
s1=0;
for(int i=1;i<=2*n-1;++i)
if( a[i]!=a[i+1]) s1++;
printf("jamp=%d\n",s1);
swapp=0;
for(int i=1;i<=2*n-1;++i)
for(int j=i;j<=2*n;++j)
if( a[i]!=a[j])
{
temp=a[i];a[i]=a[j];a[j]=temp;
s=0;
for(int l=1;l<=2*n-1;++l)
{
if( a[l]!=a[l+1]) s++;
}
if( s>swapp )
{
swapp=s;i_1=i;j_1=j;
}
temp=a[i];a[i]=a[j];a[j]=temp;
}
if( swapp>0 ) printf("maxswap=%d i=%d j=%d",swapp-s1,i_1,j_1);
}
return 0;
}
/*
输入:10101100
输出:
答案:
jamp=5
maxswap=2 i=6 j=7
--------------------------------
Process exited after 7.797 seconds with return value 0
请按任意键继续. . .
*/
阅读程序 普及篇 2、【NOIP1999】
https://blog.csdn.net/dllglvzhenfeng/article/details/130978120
阅读程序 普及篇 3、【NOIP1999】
https://blog.csdn.net/dllglvzhenfeng/article/details/130978815
阅读程序 普及篇 4、【NOIP2000】
https://blog.csdn.net/dllglvzhenfeng/article/details/130978932
阅读程序 普及篇 5、NOIP2001
第三章 阅读程序 第2节 普及篇 6、【NOIP2001】
https://blog.csdn.net/dllglvzhenfeng/article/details/130917098
7、NOIP2002 第三章 阅读程序 第2节 普及篇(C)
#include <iostream>
#include <cstdio>
using namespace std;
int a[21],i,j,k,n,l0,l1,lk,num=0;
int main( )
{
scanf("%d%d",&n,&k);
for(i=0;i<=n-1;++i) a[i]=i+1;
a[n]=a[n-1];
l0=n-1;
lk=n-1;
for(i=1;i<=n-1;++i)
{
l1=l0-k;
if( l1<0 ) l1=l1+n;
if( l1==lk)
{
a[l0]=a[n];
lk=lk-1;
a[n]=a[lk];
l0=lk;
}
else
{
a[l0]=a[l1];
l0=l1;
}
}
a[l0]=a[n];
cout<<num<<endl;
for(i=0;i<=n-1;++i) printf("%4d",a[i]);
printf("\n");
return 0;
}
/*
程序的功能,将1-n循环右移k位
输入:10 4
输出:
答案:7 8 9 10 1 2 3 4 5 6
*/
8、NOIP2002
#include <stdio.h>
#include <cstdio>
using namesapce std;
int a[11],i,j,s,sp1;
bool p;
int main(){
sp1=1;
a[1]=2;
j=2;
while(sp1<10){
j++;
p=true;
for(i=2;i<=j-1;i++)
if(j%i==0) p=false;
if(p){//开始将该段if放在for循环中,答案不对,后将该段if移出for循环,答案正确
sp1++;
a[sp1]=j;
}
}
j=2;
p=true;
while(p){
s=1;
for(i=1;i<=j;i++) s*=a[i];
s++;
for(i=2;i<=s-1;i++)
if(s%i==0) p=false;
j++;
}
printf("%d\n",s);
return 0;
}
/*
输出:
答案:30031
*/