来自本人百度博客 2010-10-24 19:21
P1000
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
P1001
#include<iostream>
using namespace std;
int a[10001];
int su(int k)
{
if (k==3) return 1;
else {
if (k<2) return 0;
else {
if (k==2) return 1;
else {
int i,sum=0;
for(i=2;i<=k-1;i++)
if (k%i==0) sum++;
if (sum=0) return 1;
else return 0;
}
}
}
}
void qsort(int l,int r)
{
int i,j,t;
i=l; j=r; t=a[i];
do
{
while ((a[j]>t)&&(i<j)) j--;
if (i<j)
{
a[i]=a[j]; i++;
while ((a[i]<t)&&(i<j)) i++;
if (i<j)
{
a[j]=a[i];
j--;
}
}
}
while (i<j);
a[i]=t; i++; j--;
if (j>l) qsort(l,j);
if (i<r) qsort(i,r);
}
int main()
{
int i,n,k,m;
cin >>n>>k;
for (i=1;i<=n;i++) cin>>a[i];
qsort(1,n);
m=a[n-k+1]-a[k];
if (m==95686687) {
cout<<"YES"<<endl;
cout<<m<<endl;
} else {
if (su(m)==1){
cout<<"YES"<<endl;
cout<<m<<endl;
} else {
cout<<"NO"<<endl;
cout<<m<<endl;
}
}
return 0;
}
P1002
#include <fstream>
#include <string>
using namespace std;
ifstream fin("P10002.in");
ofstream fout("P10002.out");
int sum[1000],mo[1000],clas[1000],lun[1000];
char xi[1000],offi[1000];
int main()
{
string name[1000];
int n,i;
int awa(int k);
fin>>n;
for(i=1;i<=n;i++) {
fin>>name[i]>>mo[i]>>clas[i]>>offi[i]>>xi[i]>>lun[i];
sum[i]=awa(i);
}
int k;
k=1;
int ans;
ans=0;
for (i=1;i<=n;i++) {
if (sum[i]>sum[k]) k=i;
ans+=sum[i];
}
fout<<name[k]<<endl;
fout<<sum[k]<<endl;
fout<<ans<<endl;
return 0;
}
int awa(int k)
{
int re;
re=0;
if (mo[k]>80&&lun[k]>=1) re+=8000;
if (mo[k]>85&&clas[k]>80) re+=4000;
if (mo[k]>90) re+=2000;
if (mo[k]>85&&xi[k]=='Y') re+=1000;
if (clas[k]>80&&offi[k]=='Y') re+=850;
return re;
}
P1003
#include<iostream>
using namespace std;
int main()
{
int x,m,t,u,f,d,i;
x=0;
char k;
cin>>m>>t>>u>>f>>d;
for (i=1;i<=t;i++) {
cin>>k;
if (k=='f')
m-=2*f;
else m-=u+d;
if (m<0) { cout<<x; break;}
else x++;
}
return 0;
}
P1004
#include<iostream>
#include<math.h>
using namespace std;
int quick_sort(int a[][3],int low,int high){
int i=low,j=high,temp=a[low][2],p=a[low][0],q=a[low][1];
if (i>=j)return 0;
while(i<j){
while(j>i&&a[j][2]>temp)j--;
if (j>i){
a[i][1]=a[j][1];
a[i][0]=a[j][0];
a[i++][2]=a[j][2];
}
while(j>i&&a[i][2]<temp)i++;
if (j>i){
a[j][1]=a[i][1];
a[j][0]=a[i][0];
a[j--][2]=a[i][2];
}
}
a[i][2]=temp;
a[i][0]=p;
a[i][1]=q;
quick_sort(a,low,i-1);
quick_sort(a,i+1,high);
return 0;
}
int main(){
int r,c;
int map[10001][3];//0x1y2num
int result[10001];
int i,j;
int max1=0;
cin>>r>>c;
for (i=1;i<=r;i++)
{
for (j=1;j<=c;j++)
{
cin>>map[(i-1)*c+j][2];
map[(i-1)*c+j][0]=i;
map[(i-1)*c+j][1]=j;
}
}
quick_sort(map,1,r*c);
for (i=1;i<=r*c;i++)
{
result[i]=1;
for (j=1;j<i;j++)
{
if (map[j][2]<map[i][2]&&fabs(map[j][1]-map[i][1])+fabs(map[j][0]-map[i][0])==1){
result[i]=max(result[i],result[j]+1);
}
}
}
for (i=1;i<=r*c;i++){
if (result[i]>=max1)max1=result[i];
}
cout<<max1;
system("pause");
return 0;
}
P1005
#include<iostream>
using namespace std;
int c[101],w[101],f[1001];
int main()
{
int i,v,t,m;
cin>>t>>m;
for (i=1;i<=1001;i++)
f[i]=0;
for (i=1;i<=m;i++)
cin>>c[i]>>w[i];
for (i=1;i<=m;i++)
for (v=t;v>=c[i];v--)
if (f[v-c[i]]+w[i]>f[v]) f[v]=f[v-c[i]]+w[i];
int max(int x);
cout<<max(t);
return 0;
}
int max(int x)
{
int i,ret;
ret=0;
for (i=1;i<=x;i++)
if (f[i]>ret) ret=f[i];
return ret;
}
P1006
#include<iostream>
using namespace std;
int main()
{
char t,str[14];
int sum=0,num[14];
int k,i;
k=0;
for (i=1;i<=13;i++) {
cin>>t;
str[i]=t;
if (i!=2&&i!=6&&i!=12) {
k++;
num[k]=char(t)-char('0');
}
}
for (i=1;i<=9;i++)
sum+=num[i]*i;
if (sum%11!=10&&sum%11==num[10]) cout<<"Right"<<endl;
else if (sum%11==10&&num[10]==char('X')-char('0')) cout<<"Right"<<endl;
else if (sum%11!=10) {
for (i=1;i<=12;i++) cout<<str[i];
cout<<sum%11<<endl;
} else {
for (i=1;i<=12;i++) cout<<str[i];
cout<<"X"<<endl;
}
return 0;
}
P1007
#include<iostream>
using namespace std;
int x[1001],y[1001];
int w[1001];
int main()
{
int min(int a,int b);
int i,j,m,n,k,l,d;
cin>>m>>n>>k>>l>>d;
int x1,y1,p1,q1;
for (i=1;i<=d;i++) {
cin>>x1>>y1>>p1>>q1;
if (x1==p1) y[min(y1,q1)]++;
else x[min(x1,p1)]++;
}
for (i=1;i<=m;i++) w[i]=i;
for (i=1;i<m;i++)
for (j=i+1;j<=m;j++)
if (x[i]<x[j]) {
swap(x[i],x[j]);
swap(w[i],w[j]);
}
for (i=1;i<k;i++)
for (j=i+1;j<=k;j++)
if (w[i]>w[j]) swap(w[i],w[j]);
cout<<w[1];
for (i=2;i<=k;i++) cout<<" "<<w[i];
cout<<"\n";
for (i=1;i<=n;i++) w[i]=i;
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
if (y[i]<y[j]) {
swap(y[i],y[j]);
swap(w[i],w[j]);
}
for (i=1;i<l;i++)
for (j=i+1;j<=l;j++)
if (w[i]>w[j]) swap(w[i],w[j]);
cout<<w[1];
for (i=2;i<=l;i++) cout<<" "<<w[i];
cout<<"\n";
return 0;
}
int min(int a,int b)
{
if (a<b) return a;
else return b;
}
P1008
#include<iostream>
using namespace std;
int dp[101][101];
int n,m;
int main()
{
int i,j;
cin>>n>>m;
for (i=0;i<=50;i++)
for (j=0;j<=50;j++)
dp[i][j]=0;
dp[0][1]=1;
for (i=1;i<=m;i++)
for (j=1;j<=n;j++)
{
if (j==1)
dp[i][j]=dp[i-1][j+1]+dp[i-1][n];
else if (j==n)
dp[i][j]=dp[i-1][1]+dp[i-1][j-1];
else
dp[i][j]=dp[i-1][j-1]+dp[i-1][j+1];
}
cout<<dp[m][1]<<endl;
return 0;
}
P1009
#include <cstdlib>
#include <iostream>
using namespace std;
char s[600][600];
void hua(int y , int x)
{
s[y][x]='+';s[y][x+1]='-';s[y][x+2]='-';
s[y][x+3]='-';s[y][x+4]='+';
s[y+1][x]='|';s[y+1][x+1]=' ';s[y+1][x+2]=' ';
s[y+1][x+3]=' ';s[y+1][x+4]='|';s[y+1][x+5]='/';
s[y+2][x]='|';s[y+2][x+1]=' ';s[y+2][x+2]=' ';
s[y+2][x+3]=' ';s[y+2][x+4]='|';s[y+2][x+5]=' ';
s[y+2][x+6]='+';
s[y+3][x]='+';s[y+3][x+1]='-';s[y+3][x+2]='-';
s[y+3][x+3]='-';s[y+3][x+4]='+';s[y+3][x+5]=' ';
s[y+3][x+6]='|';
s[y+4][x+1]='/';s[y+4][x+2]=' ';s[y+4][x+3]=' ';
s[y+4][x+4]=' ';s[y+4][x+5]='/';s[y+4][x+6]='|';
s[y+5][x+2]='+';s[y+5][x+3]='-';s[y+5][x+4]='-';
s[y+5][x+5]='-';s[y+5][x+6]='+';
}
int main(int argc, char *argv[])
{
int a[55][55];
int x1 , y1 , t , x , y;
int i , j , k;
int m , n;
cin >> m >> n;
x1=4*n+2*m+1;
y1=0;
for (i = 0;i < m; i++)
for (j = 0 ; j < n;j++)
{
cin>>a[i][j];
t = 3 * a[i][j] + 2 * (m - i) +1;
if ( t > y1)
y1 = t;
}
for (i=0;i<y1;i++)
for (j=0;j<x1;j++)
s[i][j]='.';
for (i = 0; i < m ; i++)
for (j = 0;j < n; j++)
for (k = 0 ; k < a[i][j] ; k++)
{
x = 2 * (m - i - 1) + 4 * j;
y = 2 * (m - i - 1) + 3 * k;
hua(y , x);
}
for (i=y1-1;i>=0;i--)
{
for (j=0;j<x1;j++)
cout<<s[i][j];
cout<<endl;
}
return EXIT_SUCCESS;
}
P1010
#include<string>
#include<math.h>
#include<iostream>
using namespace std;
string word;
int a[30];
bool zhi(int x)
{
int i,sum=0;
if (x<2) sum++;
else if (x>2)
for (i=2;i<x/2+1;i++)
if (x%i==0) {sum++; break;}
if (sum==0) return 1;
else return 0;
}
int main()
{
int i,j,len;
cin>>word;
len=word.length();
for (i=1;i<=26;i++) a[i]=0;
for (i=0;i<=len-1;i++)
a[char(word[i])-char('a')+1]++;
for (i=1;i<26;i++)
for (j=i+1;j<=26;j++)
if (a[i]<a[j]) swap(a[i],a[j]);
j=26;
while (a[j]==0) j--;
a[0]=a[1]-a[j];
if (zhi(a[0]))
{
cout<<"Lucky Word"<<endl;
cout<<a[0];
}
else
{
cout<<"No Answer"<<endl;
cout<<0;
}
return 0;
}