HPU积分赛 2019.8.18

Posted friends-a

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HPU积分赛 2019.8.18相关的知识,希望对你有一定的参考价值。

A题

给出n个数,问这n个数能不能分成奇数个连续的长度为奇数并且首尾均为奇数的序列

Codeforces849A

题解传送门

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 int a[maxm];
12 int main(int argc, char const *argv[])
13 
14     #ifndef ONLINE_JUDGE
15         freopen("/home/wzy/in.txt", "r", stdin);
16         freopen("/home/wzy/out.txt", "w", stdout);
17         srand((unsigned int)time(NULL));
18     #endif
19     ios::sync_with_stdio(false);
20     cin.tie(0);
21     int n;
22     cin>>n; 
23     int sum=0;
24     for(int i=0;i<n;i++)
25     
26         cin>>a[i];
27         a[i]&=1;
28         sum+=a[i];
29     
30     if(!(n&1))
31     
32         cout<<"No\\n";
33         return 0;
34     
35     if(!a[0]||!a[n-1])
36     
37         cout<<"No\\n";
38         return 0;
39     
40     cout<<"Yes\\n";
41     #ifndef ONLINE_JUDGE
42         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
43     #endif
44     return 0;
45 
View Code

B题

 

Codeforces872A

注意第一行和第二行出现同一个数的情况,记录一下

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 int a[maxn];
12 int b[maxn];
13 int vis[maxn];
14 int main(int argc, char const *argv[])
15 
16     #ifndef ONLINE_JUDGE
17         freopen("/home/wzy/in.txt", "r", stdin);
18         freopen("/home/wzy/out.txt", "w", stdout);
19         srand((unsigned int)time(NULL));
20     #endif
21     ios::sync_with_stdio(false);
22     cin.tie(0);
23     int n,m;
24     cin>>n>>m;
25     for(int i=0;i<n;i++)
26     
27         cin>>a[i];
28         vis[a[i]]=1;
29     
30     for(int i=0;i<m;i++)
31         cin>>b[i];
32     sort(a,a+n);
33     sort(b,b+m);
34     int flag=0;
35     for(int i=0;i<m;i++)
36     
37         if(vis[b[i]])
38         
39             cout<<b[i]<<endl;
40             flag=1;
41             break;
42         
43     
44     if(!flag)
45         cout<<min(a[0],b[0])<<max(a[0],b[0])<<endl;
46     #ifndef ONLINE_JUDGE
47         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
48     #endif
49     return 0;
50 
View Code

C题

输出四行1.00

D题

不会

E题

给出一个有n个整数的数组 a1, a2, ..., an 和一个整数k。你被要求把这个数组分成k 个非空的子段。 然后从每个k 个子段拿出最小值,再从这些最小值中拿出最大值。求这个最大值最大能为多少?

Codeforces872B

题解传送门 

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 int a[maxn];
12 int main(int argc, char const *argv[])
13 
14     #ifndef ONLINE_JUDGE
15         freopen("/home/wzy/in.txt", "r", stdin);
16         freopen("/home/wzy/out.txt", "w", stdout);
17         srand((unsigned int)time(NULL));
18     #endif
19     ios::sync_with_stdio(false);
20     cin.tie(0);
21     int n,k;
22     cin>>n>>k;
23     int maxx;
24     int place=0;
25     int minn;
26     for(int i=0;i<n;i++)
27     
28         cin>>a[i];
29         if(!i)
30         
31             maxx=a[i];
32             place=0;
33             minn=a[i];
34         
35         else if(maxx<a[i])
36             place=i,maxx=a[i];
37         minn=min(minn,a[i]);
38        
39     if(k==1)
40         cout<<minn<<endl;
41     else if(k==2)
42         cout<<max(a[0],a[n-1])<<endl;
43     else
44         cout<<maxx<<endl;
45     #ifndef ONLINE_JUDGE
46         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
47     #endif
48     return 0;
49 
View Code

F题

给出一个有n个数的序列a[1],a[2]……a[n],使得在i<=j<=k的条件下,令p*a[i]+q*a[j]+r*a[k]的值最大并输出这个值

Codeforces855D

题解传送门

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 ll Left[maxn];
12 ll Right[maxn];
13 ll a[maxn];
14 int main(int argc, char const *argv[])
15 
16     #ifndef ONLINE_JUDGE
17         freopen("/home/wzy/in.txt", "r", stdin);
18         freopen("/home/wzy/out.txt", "w", stdout);
19         srand((unsigned int)time(NULL));
20     #endif
21     ios::sync_with_stdio(false);
22     cin.tie(0);
23     int n;
24     ll p,q,r;
25     cin>>n>>p>>q>>r;
26     for(int i=0;i<n;i++)
27         cin>>a[i];
28     Left[0]=a[0]*p;
29     Right[n-1]=a[n-1]*r;
30     for(int i=1;i<n;i++)
31         Left[i]=max(Left[i-1],p*a[i]);
32     for(int i=n-2;i>=0;i--)
33         Right[i]=max(Right[i+1],r*a[i]);
34     ll ans=-INF;
35     for(int i=0;i<n;i++)
36         ans=max(ans,Left[i]+q*a[i]+Right[i]);
37     cout<<ans<<endl;
38     #ifndef ONLINE_JUDGE
39         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
40     #endif
41     return 0;
42 
View Code

G题

排下序就好了

HDU6292 

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 int a[maxn];
12 int b[maxn];
13 int main(int argc, char const *argv[])
14 
15     #ifndef ONLINE_JUDGE
16         freopen("/home/wzy/in.txt", "r", stdin);
17         freopen("/home/wzy/out.txt", "w", stdout);
18         srand((unsigned int)time(NULL));
19     #endif
20     ios::sync_with_stdio(false);
21     cin.tie(0);
22     int t;
23     int _=0;
24     cin>>t;
25     while(t--)
26     
27         int n,m;
28         cin>>n>>m;
29         for(int i=0;i<n;i++)
30             cin>>a[i];
31         for(int i=0;i<m;i++)
32             cin>>b[i];
33         sort(a,a+n);
34         sort(b,b+m);
35         cout<<"Problem "<<1000+(++_)<<":"<<endl;
36         if(!n)
37             cout<<"Shortest judge solution: N/A bytes."<<endl;
38         else
39             cout<<"Shortest judge solution: "<<a[0]<<" bytes."<<endl;
40         if(!m)
41             cout<<"Shortest team solution: N/A bytes."<<endl;
42         else
43             cout<<"Shortest team solution: "<<b[0]<<" bytes."<<endl;
44     
45     #ifndef ONLINE_JUDGE
46         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
47     #endif
48     return 0;
49 
View Code

H题

现在有n个整数,在这n个数中找出k个数,保证这k个数中任意两个数差的绝对值可以被m整除。

Codeforces876B

题解传送门

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 int a[maxn];
12 int vis[maxn];
13 bool cmp(int a,int b)
14 
15     return a>b;
16 
17 int main(int argc, char const *argv[])
18 
19     #ifndef ONLINE_JUDGE
20         freopen("/home/wzy/in.txt", "r", stdin);
21         freopen("/home/wzy/out.txt", "w", stdout);
22         srand((unsigned int)time(NULL));
23     #endif
24     ios::sync_with_stdio(false);
25     cin.tie(0);
26     int n,m,k;
27     cin>>n>>k>>m;
28     int cnt=0;
29     int num;
30     int maxx=0;
31     for(int i=0;i<n;i++)
32     
33         cin>>a[i];
34         if(!vis[a[i]%m])
35             cnt++;
36         vis[a[i]%m]++;
37         if(maxx<vis[a[i]%m])
38             maxx=vis[a[i]%m],num=a[i]%m;
39     
40     if(maxx<k)
41         cout<<"No\\n";
42     else
43     
44         int res=0;
45         cout<<"Yes\\n";
46         for(int i=0;i<n;i++)
47         
48             if(a[i]%m==num)
49             
50                 res++;
51                 cout<<a[i]<<" ";
52             
53             if(res==k)            
54                 break;
55         
56         cout<<"\\n";
57     
58     #ifndef ONLINE_JUDGE
59         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
60     #endif
61     return 0;
62 
View Code

I题

 

HDU5965

题解传送门

先固定第一个位置的雷的数量,往后递推

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e4+10;
 8 const ll mod=1e8+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 ll a[maxn];
12 // 每一列可以放多少个
13 ll dp[maxn];
14 int main(int argc, char const *argv[])
15 
16     #ifndef ONLINE_JUDGE
17         freopen("/home/wzy/in.txt", "r", stdin);
18         freopen("/home/wzy/out.txt", "w", stdout);
19         srand((unsigned int)time(NULL));
20     #endif
21     ios::sync_with_stdio(false);
22     cin.tie(0);
23     int t;
24     cin>>t;
25     while(t--)
26     
27         ms(dp,0);
28         ms(a,0);
29         string s;
30         cin>>s;
31         int l=s.length();
32         for(int i=0;i<l;i++)
33             a[i]=1LL*(s[i]-0);
34         ll ans=0;
35         // 固定第一个位置的个数
36         for(int i=0;i<3;i++)
37         
38             if(i>a[0])
39                 break;
40             dp[0]=i;
41             ll pos=1;
42             // 第一个固定之后,枚举后面的每个位置
43             int cnt=0;
44             for(int j=1;j<l;j++)
45             
46                 int res;
47                 // 第一列前面没有别的了,所以不需要考虑第一列左边的情况
48                 if(j==1)
49                     res=a[j-1]-dp[j-1];
50                 // 第j列需要放的雷的个数
51                 else
52                     res=a[j-1]-dp[j-1]-dp[j-2];
53                 // 符合要求
54                 if(res<=2&&res>=0)
55                     dp[j]=res,cnt++;
56             
57             // 如果没有枚举到最后一个位置
58             if(cnt!=l-1)
59                 continue;
60             // 如果最后两列放雷数不等于实际的个数,排除掉
61             if(dp[l-1]+dp[l-2]!=a[l-1])
62                 continue;
63             // 计算当第一列为雷数为i的总情况
64             for(int j=0;j<l;j++)
65                 if(dp[j]==1)
66                     pos<<=1,pos%=mod;
67             ans+=pos;ans%=mod;
68         
69         cout<<ans%mod<<endl;
70     
71     #ifndef ONLINE_JUDGE
72         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
73     #endif
74     return 0;
75 
View Code

J题

 

Codeforces913C

题解传送门

注意考虑两种情况

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 struct wzy
12 
13     ll bigness;
14     ll money;
15     double price;
16 p[maxn];
17 bool cmp(wzy u,wzy v)
18 
19     return u.price<v.price;
20 
21 int main(int argc, char const *argv[])
22 
23     #ifndef ONLINE_JUDGE
24         freopen("/home/wzy/in.txt", "r", stdin);
25         freopen("/home/wzy/out.txt", "w", stdout);
26         srand((unsigned int)time(NULL));
27     #endif
28     ios::sync_with_stdio(false);
29     cin.tie(0);
30     int n;
31     ll l;
32     cin>>n>>l;
33     for(int i=1;i<=n;i++)
34     
35         cin>>p[i].money;
36         p[i].bigness=(1LL<<(i-1));
37         p[i].price=1.0*p[i].money/p[i].bigness;
38     
39     sort(p+1,p+1+n,cmp);
40     ll L=l;
41     ll ans=INF;
42     ll res1=0,res2=0;
43     while(L>0)
44     
45         for(int i=1;i<=n;i++)
46         
47             // 全买这个饮料
48             res1=res2+ceil(1.0*L/p[i].bigness)*p[i].money;
49             ans=min(ans,res1);
50             // 多余的部分买别的
51             res2+=L/p[i].bigness*p[i].money;
52             L-=(p[i].bigness*(L/p[i].bigness));
53         
54     
55     ans=min(ans,res2);
56     cout<<ans<<endl;
57     #ifndef ONLINE_JUDGE
58         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
59     #endif
60     return 0;
61 
View Code

K题

矩阵快速幂

f[i]=f[i-1]+2*f[i-2]+n^3

HDU6470

题解传送门

 

L题

暴力枚举就行了

Codeforces879A

代码

技术图片
 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 #define ull unsigned long long
 4 #define ms(a,b) memset(a,b,sizeof(a))
 5 const int inf=0x3f3f3f3f;
 6 const ll INF=0x3f3f3f3f3f3f3f3f;
 7 const int maxn=1e6+10;
 8 const int mod=1e9+7;
 9 const int maxm=1e3+10;
10 using namespace std;
11 struct wzy
12 
13     ll s,d;
14 p[maxn];
15 int main(int argc, char const *argv[])
16 
17     #ifndef ONLINE_JUDGE
18         freopen("/home/wzy/in.txt", "r", stdin);
19         freopen("/home/wzy/out.txt", "w", stdout);
20         srand((unsigned int)time(NULL));
21     #endif
22     ios::sync_with_stdio(false);
23     cin.tie(0);
24     int n;
25     cin>>n;
26     for(int i=0;i<n;i++)
27         cin>>p[i].d>>p[i].s;
28     ll ans=p[0].d;
29     for(int i=1;i<n;i++)
30     
31         ans+=1;
32         ll res=p[i].d;
33         if(res>=ans)
34             ans=res;
35         else
36         
37             ll pos=ceil(1.0*(ans-res)/p[i].s);
38             ans=res+(p[i].s*pos);
39         
40     
41     cout<<ans<<endl;
42     #ifndef ONLINE_JUDGE
43         cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
44     #endif
45     return 0;
46 
View Code

 

以上是关于HPU积分赛 2019.8.18的主要内容,如果未能解决你的问题,请参考以下文章

hpu第3次积分赛

HPU暑期集训积分赛2

2021-06-14

不定积分与定积分(高等数学)

人工智能数学基础---定积分5:使用分部积分法计算定积分

微积分——曲线积分