省赛

第三届 E题

模拟题(仔细读题,小心坑点)

在模拟赛中失败的地方(注意): sS为string类型;  double sizeS=0;     stringstream sss(sS);        sss>>sizeS;

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<istream>
 4 #include<string.h>
 5 #include<algorithm>
 6 #include<fstream>
 7 #include<sstream>
 8 #include<cmath>
 9 using namespace std;
10 #define ll long long
11 int p(string s)
12 {
13     for(int i=0; i<s.length(); i++)
14         if(s[i]<'0'||s[i]>'9')
15             return 0;
16     return 1;
17 }
18 string a;
19 int main()
20 {
21     int c=0;
22     scanf("%d",&c);
23     getchar();
24     int ca =1;
25     while(c--)
26     {
27         int sum,t=0;
28         getline(cin,a);
29 
30         string st;
31         int i=0;
32         string sS="";///尺寸
33         string f="";///分辨率
34 
35         string aaa[102];///存储分割的字符串
36         int ssi=0;///尺寸下标
37         int ffi=0;///分辨率下标
38         int ww=0;///一共能分多少个字符串
39         for(istringstream sin(a); sin>>st;)
40         {
41             aaa[ww]=st;
42             if(st.find(".")>0&&st.find(".")<st.length()||p(st))
43             {
44                 sS=st;
45                 ssi=ww;
46             }
47             else if(st.find("*")>0&&st.find("*")<st.length())
48             {
49                 f=st;
50                 ffi=ww;
51             }
52             ww++;
53         }
54 
55         int l=0,r=0;
56         for(int i=0; i<f.find("*"); i++)
57             l=l*10+f[i]-'0';
58         for(int i=f.find("*")+1; i<f.length(); i++)
59             r=r*10+f[i]-'0';
60         double sizeS=0;
61         stringstream sss(sS);
62         sss>>sizeS;
63         double oo=sqrt(l*l+r*r)/sizeS;
64 
65         string shou="";
66         string wei="";
67         string tem=aaa[ffi+1];
68         for(int i=ffi+2; i<ww; i++)
69             tem=tem+" "+aaa[i];
70         for(int i=0; i<tem.length(); i++)
71             if(tem[i]==' ')wei+=" ";
72             else if(tem[i]>='A'&&tem[i]<='Z')
73                 wei=wei+(char)(tem[i]+32);
74             else
75                 wei+=tem[i];
76         shou+=aaa[0];
77         for(int i=1; i<ssi; i++)
78             shou=shou+" "+aaa[i];
79         cout<<"Case "<<ca<<": The "<<wei<<" of "<<shou<<"'s PPI is ";
80         if(sizeS==0)
81             cout<<"0.00.\n";
82         else printf("%0.2lf.\n",oo);
83         ca++;
84     }
85 }
View Code

 第三届 B题

题意: 给3棵苹果树,每棵树结苹果,每棵树上的苹果都有各自的大小和价值,现给一个背包,求出背包能容纳最大的价值。

解题思路:暴力贪心。

  1. 先找出具有最大价值的苹果数(按单位价值排序)。

  2. 暴力枚举剩下两颗树苹果能够达到的最大价值。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<string.h>
 5 using namespace std;
 6 #define ll long long
 7 struct P
 8 {
 9     int w,v;
10     double cmp;
11 } p[3];
12 bool cmp(const P a,const P b)
13 {
14     return a.cmp > b.cmp;
15 }
16 ll llmax(ll a,ll b)
17 {
18     return a>b?a:b;
19 }
20 int main()
21 {
22     int T;
23     scanf("%d",&T);
24     for(int Case = 1; Case <= T; Case++)
25     {
26         for(int i = 0; i < 3; ++i)
27         {
28             cin>>p[i].w>>p[i].v;
29             p[i].cmp=(double)p[i].v/p[i].w;
30         }
31         ll sum = 0;
32         cin>>sum;
33         sort(p,p+3,cmp);
34 
35         ll ans = 0,t=0;
36         for(int i = 0; i < p[0].w; ++i)
37             for(int j = 0; j < p[0].w; ++j)
38             {
39                 ll num = (sum-i*p[1].w-j*p[2].w);
40                 if(num>=0&&num<=sum)
41                 {
42                     t = i*p[1].v+j*p[2].v;
43                     ans =  llmax( ans, t + num/p[0].w*p[0].v );
44                 }
45             }
46         cout<<"Case "<<Case<<": "<<ans<<endl;
47     }
48     return 0;
49 }
View Code

 第二届 B题 结构体排序

第二届 C题 水题,判断输入字符串是否为 合法的变量名

第二届 D题 杨辉三角 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<string.h>
 4 using namespace std;
 5 int a[1002][1002];
 6 void init()
 7 {
 8     memset(a,0,sizeof(a));
 9     for(int i=0; i<1001; ++i)
10         a[i][0]=1;
11     for(int i=1; i<1001; ++i)
12         for(int j=1; j<1002; j++)
13         {
14             a[i][j]=a[i-1][j]+a[i-1][j-1];
15             a[i][j]%=10000003;
16         }
17 }
18 int main()
19 {
20     int T;
21     scanf("%d",&T);
22     init();
23     while(T--)
24     {
25         int n,k;
26         scanf("%d%d",&n,&k);
27         printf("%d\n",a[n][k]);
28     }
29     return 0;
30 }
View Code

 

 

 

  

posted @ 2017-04-28 22:24  马丁黄瓜啊  阅读(371)  评论(0编辑  收藏  举报