PAT 2011 秋
A : World Cup Betting
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- double sum = 0.65, cnt = ;
- double tmpW, tmpT, tmpL;
- while(cnt--)
- {
- cin >> tmpW >> tmpT >> tmpL;
- if(tmpW > max(tmpT, tmpL))
- {
- cout << "W ";sum *= tmpW;
- }
- else if(tmpT > max(tmpW, tmpL))
- {
- cout << "T "; sum *= tmpT;
- }
- else
- {
- cout << "L "; sum *= tmpL;
- }
- }
- printf("%.2f", (sum-)*);
- return ;
- }
B:The Best Rank
- #include <cstdio>
- #include <iostream>
- #include <vector>
- #include <string>
- #include <unordered_map>
- #include <algorithm>
- #include <functional>
- using namespace std;
- typedef struct NODE
- {
- string id;
- int math, english, cCode, aver;
- NODE(){}
- NODE(int m, int e, int c, int a):math(m),english(e),cCode(c),aver(a){}
- }node;
- vector<int> mathVec, engVec, cCodeVec, averVec;
- unordered_map<string, node> nodeMap;
- unordered_map<string, int> nodeFlagMap;
- void getBestRank(string tmpStr)
- {
- char typeStr[]="ACME";
- int type = , rank = ;
- for(int i = ; i < averVec.size(); ++ i)
- {
- if(averVec[i] == nodeMap[tmpStr].aver)
- {
- rank = i+;
- break;
- }
- }
- for(int i = ; i < cCodeVec.size(); ++ i)
- {
- if(cCodeVec[i] == nodeMap[tmpStr].cCode && i + < rank)
- {
- type = ;
- rank = i+;
- break;
- }
- }
- for(int i = ; i < mathVec.size(); ++ i)
- {
- if(mathVec[i] == nodeMap[tmpStr].math && i + < rank)
- {
- type = ;
- rank = i+;
- break;
- }
- }
- for(int i = ; i < engVec.size(); ++ i)
- {
- if(engVec[i] == nodeMap[tmpStr].english && i + < rank)
- {
- type = ;
- rank = i+;
- break;
- }
- }
- printf("%d %c\n", rank, typeStr[type]);
- }
- int main()
- {
- int N, M;
- cin >> N >> M;
- string tmpId;
- int tmpMath, tmpEng, tmpCode, tmpAver;
- for(int i = ; i < N; ++i)
- {
- cin >> tmpId >> tmpCode >> tmpMath >> tmpEng;
- tmpAver = (tmpMath+tmpEng+tmpCode+1.5)/;
- mathVec.push_back(tmpMath);
- cCodeVec.push_back(tmpCode);
- engVec.push_back(tmpEng);
- averVec.push_back(tmpAver);
- nodeFlagMap[tmpId] = ;
- nodeMap[tmpId] = NODE(tmpMath, tmpEng, tmpCode, tmpAver);
- }
- sort(mathVec.begin(), mathVec.end(), greater<int>());
- sort(cCodeVec.begin(), cCodeVec.end(), greater<int>());
- sort(engVec.begin(), engVec.end(), greater<int>());
- sort(averVec.begin(), averVec.end(), greater<int>());
- for(int i = ; i < M; ++ i)
- {
- cin >> tmpId;
- if(nodeFlagMap[tmpId])
- getBestRank(tmpId);
- else
- cout << "N/A" << endl;
- }
- return ;
- }
C: Battle Over Cities
查连通图个数,深搜即可。
- #include <cstdio>
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <cstdlib>
- #include <string>
- #include <unordered_map>
- #include <algorithm>
- #include <functional>
- using namespace std;
- const int INF = 0x7f7f7f7f;
- const int MAXCITY = ;
- #define CLR(a,b) memset(a,b,sizeof(a));
- int routeMap[MAXCITY][MAXCITY];
- int visitFlag[MAXCITY];
- void dfs(int u)
- {
- visitFlag[u] = ;
- for(int i = ; i <= MAXCITY; ++ i)
- {
- if(visitFlag[i] == && routeMap[u][i] == )
- {
- dfs(i);
- }
- }
- }
- int main()
- {
- int N, M, K;
- cin >> N >> M >> K;
- int tmpSt, tmpEnd;
- CLR(routeMap, 0x7f);
- for(int i = ; i < M; ++ i)
- {
- cin >> tmpSt >> tmpEnd;
- routeMap[tmpSt][tmpEnd] = ;
- routeMap[tmpEnd][tmpSt] = ;
- }
- int targetCity;
- for(int j = ; j < K; ++ j)
- {
- cin >> targetCity;
- int cnt = ;
- CLR(visitFlag, );
- visitFlag[targetCity] = ;
- for(int i = ; i <= N; ++ i)
- {
- if(visitFlag[i] == )
- {
- cnt++;
- dfs(i);
- }
- }
- cout << cnt- << endl;
- }
- return ;
- }
D :Waiting in Line
模拟即可。
注意:1.下班前没有被服务的输出Sorry
- #include <cstdio>
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <cstdlib>
- #include <string>
- #include <unordered_map>
- #include <algorithm>
- #include <functional>
- #include <queue>
- using namespace std;
- const int INF = 0x7f7f7f7f;
- #define CLR(a,b) memset(a,b,sizeof(a));
- typedef struct WINLINE
- {
- int lastTime, winId;
- queue<int> winQue;
- }winline;
- typedef struct ALLQUE
- {
- vector<int> cusQue;
- int index;
- ALLQUE():index(){}
- }allque;
- const int endTime = *;
- const int startTime = *;
- vector<int> cusTime(, );
- bool cmp(winline a, winline b)
- {
- if(a.winQue.size() != b.winQue.size())
- return a.winQue.size() < b.winQue.size();
- else
- return a.winId < b.winId;
- }
- int main()
- {
- int N, M, K, Q, tmpNum;
- allque allCustQue;
- cin >> N >> M >> K >> Q;
- for(int i = ; i < K; ++ i)
- {
- cin >> tmpNum;
- allCustQue.cusQue.push_back(tmpNum);
- }
- vector<winline> winInfo(N);
- for(int i = ; i < N; ++ i)
- {
- winInfo[i].lastTime = startTime;
- winInfo[i].winId = i;
- }
- vector<int> tmpQue;
- int maxCap = N*M, nowCap = ;
- for(int t = startTime; t < endTime; ++ t)
- {
- for(int i = ; i < N; ++ i)
- {
- while(!winInfo[i].winQue.empty() && winInfo[i].winQue.front() <= t)
- {
- winInfo[i].winQue.pop();
- nowCap --;
- }
- }
- while(nowCap < maxCap)
- {
- sort(winInfo.begin(), winInfo.end(), cmp);
- tmpNum = allCustQue.cusQue[allCustQue.index++] + winInfo[].lastTime;
- if(winInfo[].lastTime < endTime)
- cusTime[allCustQue.index] = tmpNum;
- winInfo[].winQue.push(tmpNum);
- winInfo[].lastTime = tmpNum;
- nowCap ++;
- if(allCustQue.index >= K)
- {
- t = endTime;
- break;
- }
- }
- }
- for(int i = ; i < Q; ++ i)
- {
- cin >> tmpNum;
- if(cusTime[tmpNum] >= startTime)
- {
- tmpNum = cusTime[tmpNum];
- printf("%02d:%02d\n", tmpNum/, tmpNum%);
- }
- else
- cout << "Sorry" << endl;
- }
- return ;
- }
PAT 2011 秋的更多相关文章
- PAT 2019 秋
考试的还行.不过略微有点遗憾,但是没想到第一题会直接上排序和dfs,感觉这次的题目难度好像是倒着的一样.哈哈哈哈. 第一题实在是搞崩心态,这道题给我的感觉是,可以做,但事实上总是差点啥. 第二题,第三 ...
- PAT 2014 秋
A 1084 Broken Keyboard 注意大小写即可. #include <cstdio> #include <iostream> #include <algor ...
- PAT 2018 秋
A 1148 Werewolf - Simple Version 思路比较直接:模拟就行.因为需要序列号最小的两个狼人,所以以狼人为因变量进行模拟. #include <cstdio> # ...
- MIT-6.006算法导论(2011秋)
L01 Algorithmic Thinking,Peak Finding 算法定义:高效处理大量数据的程序 在学本课之前最好先学习6.042,本课进阶为6.046 本门课的8个主要章节:算法思想.排 ...
- 针对局域网IM飞秋(feiq)的开发总结
先上代码了,通过java代码群发feiq消息: package com.triman.constant; import java.io.IOException; import java.io.Unsu ...
- 【Java】几道常见的秋招面试题
前言 只有光头才能变强 Redis目前还在看,今天来分享一下我在秋招看过(遇到)的一些面试题(相对比较常见的) 0.final关键字 简要说一下final关键字,final可以用来修饰什么? 这题我是 ...
- [转帖]PAT 计算机程序设计能力考试
PAT 计算机程序设计能力考试 https://blog.csdn.net/bat67/article/details/52134211 [官方简介] 计算机程序设计能力考试(Programming ...
- PAT 1080 Graduate Admission[排序][难]
1080 Graduate Admission(30 分) It is said that in 2011, there are about 100 graduate schools ready to ...
- 飞秋软件的OA消息接口服务器
由于单位使用了飞秋,同时也使用了OA,但OA的消息系统没有飞秋方便,所以大多数人还是在用飞秋沟通.但审批等流程又在OA上,所以做了个消息接口服务器,提取OA消息自动发送到飞秋上,大大方便了工作. 正好 ...
随机推荐
- ApplicationListener监听使用ContextRefreshedEvent事件类型会触发多次
@Componentpublic class TestApplicationListener implements ApplicationListener<ContextRefreshedEve ...
- DevOps - 为什么
章节 DevOps – 为什么 DevOps – 与传统方式区别 DevOps – 优势 DevOps – 不适用 DevOps – 生命周期 DevOps – 与敏捷方法区别 DevOps – 实施 ...
- NAND Flash驱动
硬件原理及分析 管脚说明 Pin Name Pin Function R/B(RnB) The R/B output indicates the status of the devic ...
- Nature
1.主干 (1)<河图+洛书>:启发伏羲作八卦. (2)<三坟+五典>:失传:伏羲.神农.轩辕.少昊.颛顼.帝喾.唐尧.虞舜. (3)<八索+九丘>:失传:八卦之书 ...
- 【LeetCode】101. 对称二叉树
题目 给定一个二叉树,检查它是否是镜像对称的. 例如,二叉树 [1,2,2,3,4,4,3] 是对称的. 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3, ...
- C语言备忘录——运算符优先级
丢脸啊,今天写一道算法题,第一次没写对.改了半天愣是没看出来错哪,后面说出了一下过程,突然发现是运算符优先级惹得祸 if (!num % 2){ …… },!的运算优先级高于%,啊啊啊,丧心病狂我找了 ...
- mfc WebBrowser打开本地网页
本地路径要用file协议,例子:file:///c:/abc/def.html注意点:file:后面是3个正斜杠,路径中用正斜杠(不是标准的反斜杠).如果你觉得IE地址栏支持标准的路径写法,那么你就错 ...
- 批处理+7zip解压用纯数字加密的压缩包zip
@echo off set path=c:\Program Files\7-Zip; for /L %%i in (0,1,100000) do ( call :myfunc %%i ) goto : ...
- 逆战:微信小程序
微信小程序的生命周期 onLaunch: function(options) { // ...
- 从零开始学C++(0 简介)
2020年,给自己定一个新目标————开始写技术博客,将之前所学的内容重新复习并整理成一系列的文章,一来可以让自己对这些基础知识更加熟悉,二来方便于以后的复习查阅. 以前自己都是以笔记的形式将知识点记 ...