2018.9.8 第一次参加 PAT 甲级代码

第一题,史上最坑的20分题目,提交3000多,通过率0.04;

我过了两个测试点 8分,用时 1小时20分;

# include <iostream>
# include <cstdio>
# include <vector>
# include <algorithm>
using namespace std;
const int maxn = 111;
int judge[maxn];
int org[maxn];
struct node{
	int a, b;
	node(int _a, int _b){
		a = _a, b = _b;
	}
};
vector<node> v;
bool cmp(node a, node b){
	if(a.a != b.a) return a.a < b.a;
	else return a.b < b.b;
}

int main(){
	freopen("C:\\1.txt", "r", stdin);
	int n, num = 0;
	scanf("%d", &n);
	for(int i = 1, per; i <= n; i++){
		scanf("%d", &org[i]);
	}
	for(int i = 1; i <= n; i++){ // mei ju 1 is false
		for(int j = i+1; j <= n; j++){ // mei ju 2 is false
			fill(judge, judge + maxn, 0);
			vector<int> vtmp;
			int tmp1 = org[i], tmp2 = org[j];
			int numw = 0, flag = 0, flag1 = 0;
			org[i] = 0 - org[i];
			org[j] = 0 - org[j];
			for(int k = 1; k <= n; k++){
				int tmp = abs(org[k]);
				if(judge[tmp] == 0 && org[k] > 0){
					judge[tmp] = org[k];
					cout << judge[tmp] << ' ' <<  org[k] << endl;
				}
				else if(judge[tmp] == 0 && org[k] < 0){
					judge[tmp] = org[k];
					numw++;
					if(tmp == i || tmp == j) flag1 = 1;
					vtmp.push_back(tmp);
					cout << judge[tmp] << ' ' <<  org[k] << endl;
				} 
				else if(judge[tmp] != 0){
					if(org[k] != judge[tmp]){
						flag = 1;
					}
					cout << judge[tmp] << ' ' <<  org[k] << endl;
				}
			}
			if(numw == 2 && flag == 0 && flag1 == 1){
				v.push_back(node(vtmp[0], vtmp[1]));
			}
			org[i] = tmp1, org[j] = tmp2;
			cout << endl;
		}
	}
	sort(v.begin(), v.end(), cmp);
	if(v.size() == 0) printf("No Solution\n");
	else printf("%d %d\n", v[0].a, v[0].b);
}

 

第二题 不算难,2000多提交, 通过率 0.1+;

有一个测试点没过去, 22 分, 用时 30多分钟;

# include <iostream>
# include <cstdio>
# include <vector>
# include <algorithm>
using namespace std;
const int maxn = 1e6+ 10;
vector<int> v[maxn];
bool judge[maxn] = {false};

int main(){
	freopen("C:\\1.txt", "r", stdin);
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 0, a, b; i < n; i++){
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i = 0, k; i < m; i++){
		int flag = 0;
		fill(judge, judge +maxn, false);
		scanf("%d", &k);
		for(int j = 0, tmp; j < k; j++){
			scanf("%d", &tmp);
			judge[tmp] = true;
			for(int x = 0; x < v[tmp].size(); x++){
				if(judge[v[tmp][x]] == true){
					printf("No\n");
					flag = 1;
				}
				
			}
		}
		if(flag == 0) printf("Yes\n");
		flag = 0;
	}
}

 

第三题 提交2000多, 通过 0.1+;

有一个测试点没过, 22 分, 用时 1小时;

# include <iostream>
# include <algorithm>
# include <cstdio>
# include <vector>
using namespace std;
const int maxn = 222;
const int inf = 1e9;
int G[maxn][maxn];

int main(){
	freopen("C:\\1.txt", "r", stdin);
	fill(G[0], G[0] +maxn*maxn, inf);
	int n, m, k, mindist = inf, dian;
	scanf("%d%d", &n, &m);
	for(int i = 0, a, b, distance; i < m; i++){
		scanf("%d%d%d", &a, &b, &distance);
		G[a][b] = G[b][a] = distance;
	//	cout << a << ' ' << b << distance << endl;
	}
	scanf("%d", &k);
	for(int i = 1, num; i <= k; i++){
		int dist = 0, flag = 0;
		vector<int> v;
		scanf("%d", &num);
		for(int j = 0, tmp; j < num; j++){
			scanf("%d", &tmp);
			v.push_back(tmp);
			if(j == 0) continue;
		//	cout << G[v[j-1]][v[j]] << endl;
			if(G[v[j-1]][v[j]] == inf){
				dist = -1;
				flag = -1;
			} 
			else dist += G[v[j-1]][v[j]];
		}
		if(dist < mindist && flag != -1 && num >= n+1 && v[0] == v[v.size() -1]){
			mindist = dist;
			dian = i;
		}
		if(flag == -1) printf("Path %d: NA", i);
		else printf("Path %d: %d", i, dist);
		if(v[0] != v[v.size() - 1]) flag = -1;
		if(flag == -1 || num < n+1) printf(" (Not a TS cycle)\n");
		else if(num > n + 1) printf(" (TS cycle)\n");
		else if(num == n + 1) printf(" (TS simple cycle)\n");
	}
	printf("Shortest Dist(%d) = %d\n", dian, mindist);
	return 0;
}

 

第四题,提交 < 1000, 通过率0.05, 因为第一题,实在没时间了,又想着30分题都很难,看都没看;

0分,用时0;

事后和别人讨论,才知道不难,经常被 30 分的题虐,导致自己根本没想着做出来。

大概就是 根据前中序建二分查找树(这个很熟练,我可以默写出来);

给你两个叶子节点,判断他们的父节点,输出格式化,大概这个意思,具体我也不清楚;

感觉自己不死怼那个巨坑的 20 分题,这题起码可以 15+啊,很烦;

 

52 = 8 + 22 + 22 + 0;

总结这次考试的失败经验,不管是 20 分题还是 30 分题,一定要读完题目,万一自己会呢;

考试最好用 VS,Devc++ 调试太慢了,我第三题调了半天,手动断点,试数据,很耗时。

还好的是,考试碰到几个不错的同学,都很厉害,起码这点是开心的。

发证书时,老师说我考得不错,也不知道是个什么意思,可能在苏大考甲级的都不是很强吧;

可怜我这个机械狗,学习半年不到,就要和那些计算机的老油子怼,苦啊!!!

 

今年12月份苏大再战。

附上博主的惨照

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值