欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

2019.3.14解题报告&补题报告

程序员文章站 2022-12-08 22:48:12
A题 题意: 输入r, c,代表r*c的矩阵,接下来一行,是r个数,代表每一行里最大的数;接下来一行,是c个数,代表每一列中的最大数。求所给数据是否冲突。 思路:判断r个数中最大数maxr和c个数中最大数maxc是否相等,相等即能构造矩阵,否则不能。原因是maxr和maxc都是矩阵最大值,只有两数相 ......

a题

题意:

输入r, c,代表r*c的矩阵,接下来一行,是r个数,代表每一行里最大的数;接下来一行,是c个数,代表每一列中的最大数。求所给数据是否冲突。

思路:判断r个数中最大数maxr和c个数中最大数maxc是否相等,相等即能构造矩阵,否则不能。原因是maxr和maxc都是矩阵最大值,只有两数相等才可能构成矩阵。

代码:

 1 #include<bits/stdc++.h>
 2 
 3 #define vint vector<int>
 4 #define vstr vector<string>
 5 #define vll vector<long long>
 6 #define ll long long
 7 #define ull unsigned long long
 8 #define pf printf
 9 #define sf scanf
10 #define sfd(n) scanf("%d", &n)
11 #define sflf(n) scanf("%lf", &n)
12 #define sfll(n) scanf("%lld", &n)
13 #define pfd(n) printf("%d", n)
14 #define pflf(n) printf("%lf", n)
15 #define pfll(n) printf("%lld", n)
16 #define pft    printf("\t")
17 #define pfn printf("\n")
18 #define pfk printf(" ")
19 #define pi 3.1415926
20 #define max 100000
21 
22 using namespace std;
23 
24 int n, m;
25 int a[105], b[105];
26 
27 int main() {
28     cin >> n >> m;
29     int maxr = -1, maxc = -1;
30     for (int i = 1; i <= n; i++) {
31         cin >> a[i];
32         maxr = max(maxr, a[i]);
33     }
34     for (int i = 1; i <= m; i++) {
35         cin >> b[i];
36         maxc = max(maxc, b[i]);
37     }
38     if( maxr==maxc ) {
39         cout << "possible" << endl;
40     }else {
41         cout << "impossible" << endl;
42     }
43          
44 
45     return 0;
46 }

 

f题

题意:

给定n, 且n = m^2 - k^2 ,求m,k。

思路:

设m = k+x;

则m^2 - k^2 = 2*x*k+x^2

即n = 2*x*k+x^2 ,    x、k是正整数

所以当x是奇数时,n为奇数;当x是偶数时,n是4的倍数;

所以

  • n是奇数:x可以取1,即n = 2*k+1, m = k+1;
  • n是4的倍数:x取2,即n = 4*k+4, m = k+2;
  • n%2==0&&n%4!=0: 无法满足式子;

 

代码:

 1 #include<bits/stdc++.h>
 2 
 3 #define vint vector<int>
 4 #define vstr vector<string>
 5 #define vll vector<long long>
 6 #define ll long long
 7 #define ull unsigned long long
 8 #define pf printf
 9 #define sf scanf
10 #define sfd(n) scanf("%d", &n)
11 #define sflf(n) scanf("%lf", &n)
12 #define sfll(n) scanf("%lld", &n)
13 #define pfd(n) printf("%d", n)
14 #define pflf(n) printf("%lf", n)
15 #define pfll(n) printf("%lld", n)
16 #define pft    printf("\t")
17 #define pfn printf("\n")
18 #define pfk printf(" ")
19 #define pi 3.1415926
20 #define max 100000
21 
22 using namespace std;
23 
24 int main() {
25     ll n, m, k;
26     bool f = true;
27     cin >> n;
28     if( n%2!=0 ) {
29         k = (n-1)/2;
30         m = k+1;
31     }else if( n%4==0 ){
32         k = (n-4)/4;
33         m = k+2;
34     }else {
35         f = false;
36     }
37     if( f ) {
38         cout << m << " " << k;
39     }else {
40         pf("impossible");
41     }
42 
43     return 0;
44 }

i题

题意:

求公式最大值

思路:

sos保存前k项的平方和,sum保存后(n-k)项的和,

遍历k,求最大值

代码:

 1 #include<bits/stdc++.h>
 2 
 3 #define vint vector<int>
 4 #define vstr vector<string>
 5 #define vll vector<long long>
 6 #define ll long long
 7 #define ull unsigned long long
 8 #define pf printf
 9 #define sf scanf
10 #define sfd(n) scanf("%d", &n)
11 #define sfc(n) scanf("%c", &n)
12 #define sflf(n) scanf("%lf", &n)
13 #define sfll(n) scanf("%lld", &n)
14 #define pfd(n) printf("%d", n)
15 #define pfc(n) printf("%c", n)
16 #define pflf(n) printf("%lf", n)
17 #define pfll(n) printf("%lld", n)
18 #define pft    printf("\t")
19 #define pfn printf("\n")
20 #define pfk printf(" ")
21 #define pi 3.1415926
22 #define max 100000
23 
24 using namespace std;
25 
26 int main() {
27     int n;
28     cin >> n;
29     int* num = new int[n];
30     cin >> num[0];
31     ll sos = num[0]*num[0], sum = 0, max = 0, ans;
32     for( int i=1; i<n; i++ ) {
33         cin >> num[i];
34         sum += num[i];
35     }
36     for( int k=1; k<n; k++ ) {
37         ans = sos*sum;
38         if( max<ans ) {
39             max = ans;
40         }
41         sos += num[k]*num[k];
42         sum -= num[k];
43     }
44     pfll(max);
45 
46     return 0;
47 }