AutoX安途杯中山大学程序设计校赛(同步赛)

比赛链接

AutoX安途杯中山大学程序设计校赛(同步赛)

C.Lucky Matrix

时间限制:C/C++ 1秒,其他语言2空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld

题目描述

A matrix[ABCDEFGHI] is a Lucky Matrix if and only if A,B,C,D,E,F,G,H,I are all integers and A+B+C=D+E+F=G+H+I=A+D+G=B+E+H=C+F+I=A+E+I=C+E+G.

For example, these are Lucky Matrices:
[672159834][111111111] [110101011]

However, these are NOT Lucky Matrices: (Pay attention that in a Lucky Matrix all the 9 numbers must be integers.)
[123456789] [100.500.510.510] [000.7510.250.50.250.50.5]

Now you are given the three integers A,B,D in the matrix, and you need to determine the values of C,E,F,G,H,I such that the matrix is a Lucky Matrix.

输入描述:

The first line of input contains an integer T (1T20000), denoting the number of test cases.
Each test case contains three integers A,B,D in one line. 106A,B,D106.

输出描述:

For each test case, print 6 integers C,E,F,G,H,I in one line, denoting your answer.
If there is no solution, print "-1". If there are multiple solutions, you can print any one of them.

输入

5 6 7 1 1 1 1 -1 1 1 1 0 0 0 0 1

输出

2 5 9 8 3 4 1 1 1 1 1 1 0 0 -1 0 -1 1 -1 -1

解题思路

数学

A+B+C=x,则 G=xAD,C=xAB,H=xBE,F=xDE,由 G+H+I=C+F+I=A+E+I,即 G+H=xAD+xBE=C+F=xAB+xDE=A+E,得 2E=2x2ABD,又有 C+E+G=E+xAB+xAD=x,得 2E=4A2B2D2x,故有:2x2ABD=4A2B2D2x,解得 x=6A+3B+3D4

  • 时间复杂度:O(1)

代码

#include<cstdio> using namespace std; int main() { int t; for(scanf("%d",&t);t;t--) { int a,b,d; scanf("%d%d%d",&a,&b,&d); int k=6*a+3*b+3*d; if(k%4)puts("-1"); else { k/=4; int c=k-a-b,g=k-a-d,e=k-c-g,f=k-d-e,h=k-b-e,i=k-a-e; printf("%d %d %d %d %d %d\n",c,e,f,g,h,i); } } return 0; }

D.Determinant

时间限制:C/C++ 1秒,其他语言2空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld

题目描述

HZ is doing homework. The answer to a problem is a 2×2 matrix. After trying for several hours, he finally solved it. But unfortunately, one of the four numbers in the matrix is replaced by x by accident. Besides the three remaining numbers, he only remembers that the determinant of the matrix is bigger than zero. Now your task is to compute the range of x.
输入描述:
The first line of input contains an integer T (1T105), denoting the number of test cases.

Each test case contains four elements A,B,C,D, denoting the matrix [ABCD]. One of the elements is replaced by xx while the remaining three are integers.

30A,B,C,D30. (This is the range of the three given integers, not the range of x. x can be any real number.)

输出描述:

For each test case, print your answer in one line:
If the range of x is all real numbers, print "R";

If the range of x is empty set, print "E";
Otherwise, print "x>p/q" or "x<p/q" (q>0, |p| and qq are coprime). Specially, if q=1, you should only print "x>p" or "x<p".

输入

11 x 2 3 4 1 x 3 4 1 2 x 4 1 2 3 x x 2 3 -4 1 x -3 4 1 -2 x 4 -1 2 3 x x 1 -1 0 1 x 0 -1 x 0 0 1

输出

x>3/2 x<4/3 x<2 x>6 x<-3/2 x>-4/3 x>-2 x<-6 R E x>0

解题思路

二阶行列式即正对角线的乘积减去副对角线的乘积,模拟一遍即可,关键在于找 x 的字符串的处理~

  • 时间复杂度:O(1)

代码

#include<bits/stdc++.h> using namespace std; string s; int T; string num[4]; int main() { cin>>T; cin.ignore(); while(T--) { getline(cin,s); int n=s.size(); int cnt=0; int pos=s.find(' '),lst=0; while(pos!=-1) { num[cnt++]=s.substr(lst,pos-lst); lst=pos+1; pos=s.find(' ',pos+1); } num[cnt++]=s.substr(lst,n-lst); int a,b,c; if(num[0]=="x"||num[3]=="x") { a=num[0]=="x"?stoi(num[3]):stoi(num[0]); b=stoi(num[1]); c=stoi(num[2]); int t=b*c; if(a==0) puts(t<0?"R":"E"); else if(a>0) { int d=__gcd(a,abs(t)); t/=d,a/=d; if(a==1) printf("x>%d\n",t); else printf("x>%d/%d\n",t,a); } else { if(t<0)a=abs(a),t=abs(t); else t=-t,a=-a; int d=__gcd(a,abs(t)); t/=d,a/=d; if(a==1) printf("x<%d\n",t); else printf("x<%d/%d\n",t,a); } } else { a=num[1]=="x"?stoi(num[2]):stoi(num[1]); b=stoi(num[0]); c=stoi(num[3]); int t=b*c; if(a==0) puts(t>0?"R":"E"); else if(a>0) { int d=__gcd(a,abs(t)); t/=d,a/=d; if(a==1) printf("x<%d\n",t); else printf("x<%d/%d\n",t,a); } else { if(t<0)a=abs(a),t=abs(t); else t=-t,a=-a; int d=__gcd(a,abs(t)); t/=d,a/=d; if(a==1) printf("x>%d\n",t); else printf("x>%d/%d\n",t,a); } } } return 0; }

E.Sequence I

时间限制:C/C++ 1秒,其他语言2空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld

题目描述

You are given a sequence of length N. Each time you can delete two adjacent numbers, and insert the absolute value of their difference in the corresponding position. What is the mininum number you can get after N1 operations? (The number you get means the only one integer left after N1 operations.)

输入描述:

The first line of input contains an integer T (1T1000), denoting the number of test cases.
Each test case contains two lines:
The first line contains one integer N (2N8), denoting the length of the sequence;
The second line contains N integers A1,A2,,AN (0Ai106), denoting the sequence.

输出描述:

For each test case, print one integer in one line, denoting your answer.

输入

5 2 1 1 2 2 3 2 3 2 3 999 1 1 4 80 87 50 54

输出

0 1 1 997 3

解题思路

暴力dfs

数据量较小,可暴力dfs,即每次操作枚举任意一个数进行操作,再输出多出来的数与插入新数~

  • 时间复杂度:O(n!)

代码

#include<bits/stdc++.h> using namespace std; int t,n; vector<int> a; int res; int op; void dfs(int op) { if(op==0) { res=min(res,a[0]); return ; } for(int i=0;i+1<a.size();i++) { auto tmp=a; int t=abs(a[i]-a[i+1]); a.erase(a.begin()+i,a.begin()+i+2); a.insert(a.begin()+i,t); dfs(op-1); a=tmp; } } int main() { for(scanf("%d",&t);t;t--) { scanf("%d",&n); a.clear(); for(int i=1;i<=n;i++) { int x; scanf("%d",&x); a.push_back(x); } res=0x3f3f3f3f; op=n-1; dfs(op); printf("%d\n",res); } return 0; }

__EOF__

本文作者acwing_zyy
本文链接https://www.cnblogs.com/zyyun/p/15415707.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   zyy2001  阅读(249)  评论(2编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示