这次比赛由于有事请假了,,所以抽空问同学要来代码看了看(所以以下代码并不是我写的,我只是分析了一下,加了注释)
A. Architecture
只需要输入后找出两行的最大值比较就可以了,如果最大值不相同就不行
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #include <cmath> 5 #include <string> 6 #include <cstring> 7 #include <map> 8 using namespace std; 9 const long long N = 1e9 + 7; 10 typedef long long ll; 11 map <char,int> ma; 12 13 int main() 14 { 15 int n,m,nmax = 0,mmax = 0; 16 int num; 17 cin >> n >> m; 18 for(int i = 0;i < n;i++) 19 { 20 scanf("%d",&num); 21 nmax = max (num,nmax);//求第一个最大值 22 } 23 for(int i = 0;i < m;i++) 24 { 25 scanf("%d",&num); 26 mmax = max (num,mmax);//求第二个最大值 27 } 28 if(mmax != nmax)//比较最大值 29 cout << "impossible" << endl; 30 else 31 cout << "possible" << endl; 32 33 return 0; 34 }
I. Inquiry I
提供一组数长度为n,找出一个k,使得位置为1~k的平方和 与 位置为k+1~n的和 的乘积最大
n的范围很大,很容易超时,通过求前缀和解决(为了看懂同学的代码又去补了一波前缀和,,,妙啊,,)
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #include <cmath> 5 #include <string> 6 #include <cstring> 7 #include <map> 8 using namespace std; 9 const long long N = 1e9 + 7; 10 typedef long long ll; 11 map <char,int> ma; 12 ll a[1000010]; 13 ll b[1000010]; 14 int main() 15 { 16 int n,num; 17 ll maxnum = -1; 18 scanf("%d",&n); 19 for(int i = 1;i <= n;i++) 20 { 21 scanf("%d",&num); 22 a[i] = a[i-1] + num; 23 b[i] = b[i-1] + num * num; 24 } 25 for(int k = 1;k <= n-1;k++) 26 { 27 ll sum1 = b[k]; 28 ll sum2 = a[n] - a[k]; 29 maxnum = max(maxnum ,sum1*sum2); 30 31 } 32 33 printf("%lld\n",maxnum); 34 return 0; 35 }