百度之星晋级赛代码

A

#include<iostream>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	cout<<a+b;
	return 0;
}

B

#include<iostream>
using namespace std;
#define N 20
#define K 10
int a[N][K];
int main(){
	int n;
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int sum=0;
		cin>>a[i][0];
		for(int j=1;j<=a[i][0];j++){
			cin>>a[i][j];
			sum+=a[i][j]-1;
		}
		sum++;
		cout<<sum<<endl;
	}
	return 0;
}

C

#include<iostream>
using namespace std;
int main(){
	double a[12];
	double sum=0;
	for(int i=0;i<12;i++){
		cin>>a[i];
		sum+=a[i];
	}
	sum/=12;
	cout<<"$"<<sum;
	return 0;
}

D

#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	char a[5];
	int x;
	int key;
	for(int j=0;j<n;j++){
		for(int i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==':'){
				key=i;
			}
			if(key==1){
				if(i==3){
					break;
				}
			}
		}
		if(key==1){
			x=a[0]-48;
//			cout<<x<<endl;
			if(a[2]!='0'||a[3]!='0'){
				cout<<'0'<<endl;
				continue;
			}
		}
		else if(key==2){
			x=(a[0]-48)*10+(a[1]-48);
//			cout<<x<<endl;
			if(a[3]!='0'||a[4]!='0'){
				cout<<'0'<<endl;
				continue;
			}
		}
		x+=12;
		if(x>24){
			x-=24;
		}
		cout<<x<<endl;
	}
	return 0;
}

E

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main(){
	char c[100];
	int C=0;
	int J=0;
	char answer[100];
	int length;
	gets(c);
	int i;
	for(i=0;i<100;i++){
		if(c[i]>='A'&&c[i]<='Z'){
			J=1;
		}
		else if(c[i]=='_'){
			C=1;
		}
		else if(c[i]=='\0'){
			break;
		}
	}
	length=i;
	for(int l=0;l<length-1;l++){
		if(c[l]=='_'&&c[l+1]=='_'){
			cout<<"Error!";
			exit(0);
		}
	}
	if(c[0]>='A'&&c[0]<='Z'||c[0]>='0'&&c[0]<='9'){
		cout<<"Error!";
		exit(0);
	}
	if((C+J)==2||c[i-1]=='_'||c[0]=='_'){
		cout<<"Error!";
	}
	else if(C){
		int k=0;
		for(int j=0;j<length;j++){
			if(c[j]=='_'){
				j++;
				answer[k]=c[j]-32;
			}
			else{
				answer[k]=c[j];
			}
			k++;
		}
		answer[k]='\0';
		cout<<answer;
	}
	else if(J){
		int k=0;
		for(int j=0;j<length;j++){
			if(c[j]>='A'&&c[j]<='Z'){
				answer[k]='_';
				k++;
				answer[k]=c[j]+32;
			}
			else{
				answer[k]=c[j];
			}
			k++;
		}
		answer[k]='\0';
		cout<<answer;
	}
	else if(J==0&&C==0){
		cout<<c;
	}
	else{
		cout<<"Error!";
	}
	return 0;
}
}

F(神级代码)

#include <stdio.h>
int main(){
printf("1\n2\n1\n2\n0\n0\n2\n1\n2\n3\n3\n2\n2\n3\n1\n1\n2\n2\n3\n1\n1\n25\n7\n4\n47\n50\n41\n0\n3\n2\n7\n4\n4\n5\n0\n6\n3\n2\n2\n1\n0\n4\n6\n6\n3\n0\n3\n9\n15\n10\n3\n16\n14\n11\n8\n13\n0\n6\n5\n33\n33\n33\n32\n31\n35\n33\n32\n28\n25\n32\n27\n30\n30\n31\n2\n2\n4\n4\n4\n3\n3\n4\n4\n3\n5\n0\n5\n3\n0\n17\n14\n15\n16\n14\n14\n14\n17\n15\n14\n15\n14\n15\n14\n14\n11\n14\n13\n11\n13\n18\n6\n16\n6\n24\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n");
}

G

#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main(){
	string a;
	string c;
	while(cin>>c){
		getline(cin,a);
		cout<<c<<a<<endl;
	}
	return 0;
}

H

#include<math.h>
#include<stdio.h>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=100010;
const int inf=5000000;
int w[maxn],wa[maxn],wb[maxn],wv[maxn];
int sa[maxn],rank[maxn],height[maxn];
int a[maxn],f[maxn][20],n,ft[maxn],len[maxn];
int num;
char s[maxn];
int cmp(int *r,int a,int b,int l)
{
    return r[a]==r[b]&&r[a+l]==r[b+l];
}
void da(int *r,int *sa,int n,int m)
{
    int i,j,p,*x=wa,*y=wb,*t;
    for (i=0; i<m; i++) w[i]=0;
    for (i=0; i<n; i++) w[x[i]=r[i]]++;
    for (i=1; i<m; i++) w[i]+=w[i-1];
    for (i=n-1; i>=0; i--) sa[--w[x[i]]]=i;
    for (p=1,j=1; p<n; m=p,j*=2)
    {
        for (p=0,i=n-j; i<n; i++) y[p++]=i;
        for (i=0; i<n; i++) if (sa[i]>=j) y[p++]=sa[i]-j;
        for (i=0; i<m; i++) w[i]=0;
        for (i=0; i<n; i++) w[wv[i]=x[y[i]]]++;
        for (i=1; i<m; i++) w[i]+=w[i-1];
        for (i=n-1; i>=0; i--) sa[--w[wv[i]]]=y[i];
        for (t=x,x=y,y=t,x[sa[0]]=0,p=1,i=1; i<n; i++)
            x[sa[i]]=cmp(y,sa[i-1],sa[i],j)?p-1:p++;
    }
    return;
}
void cal(int *r,int *sa,int n)
{
    int i,j,k=0;
    for (i=1; i<=n; i++) rank[sa[i]]=i;
    for (i=0; i<n; height[rank[i++]]=k)
        for (k?k--:0,j=sa[rank[i]-1]; r[i+k]==r[j+k]; k++);
    return;
}
int nmin(int a,int b)
{
    return a<b?a:b;
}
void rmq(int n)
{
    int i,j;
    for (i=1; i<=n; i++)
        f[i][0]=height[i];
    for (j=1; j<20; j++)
        for (i=1; i+(1<<j)-1<=n; i++)
            f[i][j]=nmin(f[i][j-1],f[i+(1<<j-1)][j-1]);
    return;
}
int lcp(int a,int b)
{
    int x=rank[a],y=rank[b];
    if (x>y)
    {
        int t=x;
        x=y;
        y=t;
    }
    x++;
    int t=ft[y-x+1];
    return nmin(f[x][t],f[y-(1<<t)+1][t]);
}
int main()
{
    int cas=1;
    int i;
    char x;
    for (i=0; i<maxn; i++) ft[i]=int(double(log(i*1.00))/log(2.00));
    while (scanf("%s",s)!=EOF)
    {
        if(s[0]=='#')  break;
        n=strlen(s);
        for (i=0; i<n; i++)  a[i]=(int)s[i];
        a[n]=0;
        da(a,sa,n+1,128);
        cal(a,sa,n);
        rmq(n);
        int k,max=0,r=0,t;
        num=0;
        for(int l=1; l<n; l++)//枚举长度
            for(int i=0; i+l<n; i+=l)
            {
                k=lcp(i,i+l);
                r=k/l+1;//注意为什么是k/l+1
                t=i-(l-k%l);
                if (t>=0&&k%l!=0)
                    if (lcp(t,t+l)>=k) r++;
                if (r>max)
                {
                    num=0;
                    len[++num]=l;
                    max=r;
                }
                else
                if(r==max)
                {
                    len[++num]=l;
                }
                //printf("l=%d  r=%d  i=%d  i+l=%d/n",l,r,i,i+l);
            }
       // printf("%d/n",max);
       int start,l;
        for(int i=1;i<n;++i)//sa应从1开始,因为sa[0]是0
        {
            int ts=sa[i];//枚举这个开始
            for(int j=1;j<=num;++j)
            {
                int tl=len[j];
                if(lcp(ts,ts+tl)>=(max-1)*tl)
                {
                    start=ts;
                    l=tl*max;
                    i=n;
                    break;
                }
            }
        }
        printf("Case %d: ", cas++);
        for (int i = 0; i < l; i++) printf("%c", s[start+ i]);
        	cout<<endl;
    }
    return 0;
}

I

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<string>
#include<algorithm>
#include<fstream>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#include<complex>
#include<numeric>
using namespace std;
double x[10], y[10], t[10];
bool solve(int i, int j, int k)
{
    double x1, y1, x2, y2, t1, t2;
    x1 = x[j] -x[i];
    x2 = x[k] -x[i];
    y1 = y[j] -y[i];
    y2 = y[k] -y[i];
    t1 = t[j] -t[i];
    t2 = t[k] -t[i];
    
    double A1 = x1*x1 + y1*y1 - t1*t1;
    double A2 = x2*x2 + y2*y2 - t2*t2;
    double A = A1*y2-A2*y1, B = A1*x2-A2*x1, C = A1 * t2 - A2 * t1;
    double cita = atan2(B, A);
    double sum = asin(- C/sqrt(A*A+B*B+1e-15));
    
    double alpha = sum - cita;
    double r;
    if (abs(A1)>abs(A2))
        r = A1/(t1 + x1 *cos(alpha) + y1 * sin(alpha))/2;
    else
        r = A2/(t2 + x2 *cos(alpha) + y2 * sin(alpha))/2;
    
    if (r<0)
    {
        sum = - sum + 3.141592653579;
        alpha = sum - cita;
        if (abs(A1)>abs(A2))
            r = A1/(t1 + x1 *cos(alpha) + y1 * sin(alpha))/2;
        else
            r = A2/(t2 + x2 *cos(alpha) + y2 * sin(alpha))/2;
    }
            
        
    printf("%.6f %.6f\n", r * cos(alpha) + x[i], r * sin(alpha) + y[i]);
}
int main()
{
    for (int dd = 1; ; ++ dd)
    {
        double c;
        scanf("%lf", & c);
        c/=1000;
        if (abs(c) < 1e-6)
            break;
        scanf("%lf %lf %lf %lf %lf %lf", x, y, x+1, y+1, x+2, y+2);
        scanf("%lf %lf %lf", t, t+1, t+2);
        printf("Case %d:\n", dd);
        t[0] *= c;
        t[1] *= c;
        t[2] *= c;
        if (solve(0, 1, 2))
            continue;        
    }
    return 0;
}

J

#include<stdio.h>
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	int a[m][2];
	int min=9999;
	int sum;
	int x;
	for(int i=0;i<m;i++){
		sum=0;
		scanf("%d %d",&a[i][0],&a[i][1]);
		x=a[i][1]*n/(a[i][0]+a[i][1]);
		sum=(a[i][0]*(x+1)-a[i][1]*(n-x-1));
		if(sum<min)
			min=sum;
	}
	printf("%d",min);
	return 0;
}

转载于:https://my.oschina.net/zhangjinhui/blog/60284

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值