PAT A 1113 AC代码

news/2024/6/17 16:18:48

用一个vector然后再sort一下

秒杀题

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> v;
int N;
int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		int x;
		scanf("%d",&x);
		v.push_back(x);
	}
	sort(v.begin(),v.end());
	if(N%2==0){
		printf("0 ");
	}else {
		printf("1 ");
	}
	int n1=N/2;
	int sum1=0,sum2=0;
	for(int i=0;i<n1;i++){
		sum1+=v[i];
	}
	for(int i=n1;i<N;i++){
		sum2+=v[i];
	}
	printf("%d",sum2-sum1);
	return 0;
}


http://www.niftyadmin.cn/n/826767.html

相关文章

PAT A 1114 AC 代码

并查集题目 最好直接写好findfather()和Union()函数 sort函数不能排set #include<iostream> #include<vector> #include<set> #include<algorithm> using namespace std; struct node{int sets0;int area0; }Node[10000]; struct sum_node{int sum_…

PAT A 1116 AC 代码

熟记一下素数判断的写法 其余逻辑非常简单 #include<iostream> #include<set> #include<unordered_map> #include<math.h> using namespace std; unordered_map<int,string> award; set<int> checked; int isprime(int x){int K(int)sqr…

PAT A 1117 AC 代码

采用一个数组m记录每个距离出现的次数 &#xff08;有一个测试点应该使用了超过100000的非常大的数据&#xff0c;所以对于超大的数据直接用m[100001]计数&#xff0c;因为E小于等于N&#xff0c;考虑不到100001之上的各种情况&#xff0c;并且这个测试点最终答案好像等于N&am…

excel VB.net 开发信任的解决

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>Caspol -q -u -ag All_Code -url "C:\test\WordDocument1.dll" FullTrust -n "test"转载于:https://www.cnblogs.com/Lizarus/archive/2011/05/18/2049562.html

PAT A 1118 AC代码

考察并查集 注意使用路径压缩的写法&#xff0c;否则会超时&#xff08;路径压缩后&#xff0c;findfather函数可以看作时间复杂度为O(1)的函数&#xff09; 其余都是简单并查集逻辑 #include<iostream> #include<set> using namespace std; set<int> bir…

这样才像女人

夏天了&#xff0c;去买个指甲油臭美。DD问&#xff1a;“妈妈&#xff0c;为什么要买指甲油呢&#xff1f;”“漂亮呗。”“这样才像女人&#xff0c;是不&#xff1f;”哈哈哈&#xff0c;不错。DD认为女人就该这样的。 DD执意要给我选一个嫩嫩的粉红色的&#xff0c;我说这个…

PAT A 1120 AC代码

简单题 #include<iostream> #include<vector> #include<algorithm> #include<set> using namespace std; set<int> s; vector<int> v; int main(){int N;cin>>N;for(int i0;i<N;i){int x;scanf("%d",&x);int id0;…

PAT A 1119 AC代码

前序后序转中序 理解&#xff1a;无法确定树仅有一种情况&#xff1a;当前序根的后一个与后序根的前一个相同&#xff0c;此时此根仅有左子树或者仅有右子树&#xff0c;因为此时无法确定是左还是右&#xff0c;所以不唯一&#xff0c;递推同理 #include<iostream> #in…