A 1084 Broken Keyboard

  注意大小写即可。

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string> using namespace std; int main()
{
string inStr, outStr;
cin >> inStr >> outStr;
int inIndex = , outIndex = ;
bool charFlag[]={false};
while(inIndex < inStr.size())
{
if(inStr[inIndex] == outStr[outIndex])
{
inIndex++;
outIndex < outStr.size()- ? outIndex++ : outStr[outIndex] = ' ';
}
else
{
int tmpNum = (int)inStr[inIndex++];
tmpNum = tmpNum >= 'a' ? tmpNum-'a'+'A' : tmpNum;
if(!charFlag[tmpNum])
{
charFlag[tmpNum] = ;
printf("%c", tmpNum);
}
}
}
return ;
}

A 1085 Perfect Sequence

  1.二分查找,不然会超时

  2.注意数值的范围,有些地方需要使用long long

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector> using namespace std;
typedef long long LL;
vector<int> inputNumVec;
int N, P;
int getMaxCnt(int lIndex)
{
int rIndex = inputNumVec.size()-, midIndex;
LL tmpNum = (LL)inputNumVec[lIndex]*P;
while(lIndex <= rIndex)
{
midIndex = (lIndex + rIndex) >> ;
if(inputNumVec[midIndex] > tmpNum)
rIndex = midIndex - ;
else
lIndex = midIndex + ;
}
return rIndex;
}
int main()
{
cin >> N >> P;
inputNumVec.resize(N);
for(int i = ; i < N; ++ i)
cin >> inputNumVec[i];
sort(inputNumVec.begin(), inputNumVec.end());
int maxCnt = , tmpNum;
for(int i = ; i <= inputNumVec.size()-maxCnt; ++ i)
{
tmpNum = getMaxCnt(i)-i+;
if(tmpNum > maxCnt)
maxCnt = tmpNum;
}
cout << maxCnt;
return ;
}

A 1086 Tree Traversals Again

  自己想个办法建树之后进行后续遍历即可

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack> using namespace std;
typedef long long LL;
#define NoAddr -1
typedef struct NODE
{
int val, lChild, rChild;
NODE(int v):val(v),lChild(NoAddr),rChild(NoAddr){}
}node;
vector<node> nodeVec;
stack<int> valVec;
bool coutFlag = false;
void postOrder(int tmpRoot)
{
if(tmpRoot >= nodeVec.size())
return;
if(nodeVec[tmpRoot].lChild > )
postOrder(nodeVec[tmpRoot].lChild);
if(nodeVec[tmpRoot].rChild > )
postOrder(nodeVec[tmpRoot].rChild);
coutFlag ? printf(" ") :coutFlag = true;
cout << nodeVec[tmpRoot].val;
}
int main()
{
int N, tmpNum, lastIndex = ;
string tmpStr;
bool pushFlag = true;
cin >> N;
while(N > )
{
cin >> tmpStr;
if(tmpStr == "Push")
{
cin >> tmpNum;
valVec.push(nodeVec.size());
nodeVec.push_back(NODE(tmpNum));
pushFlag ? nodeVec[lastIndex].lChild = nodeVec.size()- :
nodeVec[lastIndex].rChild = nodeVec.size()- ;
lastIndex = nodeVec.size()-;
pushFlag = true;
}
else
{
lastIndex = valVec.top();
valVec.pop();
pushFlag = false;
N--;
}
}
postOrder();
return ;
}

A 1087 All Roads Lead to Rome

  1.城市名string 和 序号index的转换

  2.Dijkstra找最短距离

  3.DFS根据题目中给出的优先级找到所需的条件

 #include <cstdio>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <unordered_map>
using namespace std;
#define NoAddr -1
#define MAX_CITY 210
#define CLR(a,b) memset(a,b,sizeof(a))
typedef long long LL;
const int INF = 0x7f7f7f7f;
int N, K;
string citySt;
int route[MAX_CITY][MAX_CITY]={};
vector<int> preVec[MAX_CITY];
vector<int> tmpPath;
vector<int> outPath;
vector<int> disVec;
vector<int> cityHappyValVec;
int minCityCnt = MAX_CITY, maxHappy = -, minPathCnt = , tmpMaxHappy = ;
unordered_map<string, int> cityToIndexMap;
unordered_map<int, string> indexToCityMap;
void Dijkstra(int u)
{
vector<bool> visitFlagVec(N, false);
disVec.resize(N, INF);
disVec[u] = ;
for(int i = ; i < N; ++ i)
{
int minDis = INF, v = -;
for(int j = ; j < N; ++ j)
if(!visitFlagVec[j] && disVec[j] < minDis)
{
minDis = disVec[j];
v = j;
}
if(v == -)
return;
visitFlagVec[v] = true;
for(int j = ; j < N; ++ j)
{
if(!visitFlagVec[j] && disVec[v] + route[v][j] < disVec[j])
{
disVec[j] = disVec[v] + route[v][j];
preVec[j].clear();
preVec[j].push_back(v);
}
else if(!visitFlagVec[j] && disVec[v] + route[v][j] == disVec[j])
{
preVec[j].push_back(v);
}
}
}
}
void dfs(int u)
{
if(u == )
{
minPathCnt ++;
tmpPath.push_back();
if(tmpMaxHappy > maxHappy)
{
maxHappy = tmpMaxHappy;
outPath = tmpPath;
minCityCnt = tmpPath.size();
}
else if(tmpMaxHappy == maxHappy && tmpPath.size() < minCityCnt)
{
outPath = tmpPath;
}
tmpPath.pop_back();
}
tmpPath.push_back(u);
tmpMaxHappy += cityHappyValVec[u];
for(int i = ; i < preVec[u].size(); ++ i)
dfs(preVec[u][i]);
tmpMaxHappy -= cityHappyValVec[u];
tmpPath.pop_back();
}
int main()
{
cin >> N >> K >> citySt;
cityHappyValVec.resize(N, );
string tmpCity, tmpSt, tmpEnd;
int tmpHappy, tmpDis, stIndex, endIndex, endCityIndex;
cityToIndexMap[citySt] = ;
indexToCityMap[] = citySt;
for(int i = ; i < N; ++ i)
{
cin >> tmpCity >> tmpHappy;
cityHappyValVec[i] = tmpHappy;
cityToIndexMap[tmpCity] = i;
indexToCityMap[i] = tmpCity;
if(tmpCity == "ROM")
endCityIndex = i;
}
CLR(route,0x7f);
while(K--)
{
cin >> tmpSt >> tmpEnd >> tmpDis;
stIndex = cityToIndexMap[tmpSt];
endIndex = cityToIndexMap[tmpEnd];
route[stIndex][endIndex] = tmpDis;
route[endIndex][stIndex] = tmpDis;
}
Dijkstra();
dfs(endCityIndex);
cout << minPathCnt << " " << disVec[endCityIndex] << " " << maxHappy << " " << (int)maxHappy/(outPath.size()-) << endl;
bool symbolFlag = false;
for(int i = outPath.size()-; i >= ; -- i)
{
symbolFlag ? printf("->") : symbolFlag = true;
cout << indexToCityMap[outPath[i]];
}
return ;
}

PAT 2014 秋的更多相关文章

  1. 2014秋C++ 第8周项目 分支程序设计

    课程主页在http://blog.csdn.net/sxhelijian/article/details/39152703.课程资源在云学堂"贺老师课堂"同步展示,使用的帐号请到课 ...

  2. PAT 2019 秋

    考试的还行.不过略微有点遗憾,但是没想到第一题会直接上排序和dfs,感觉这次的题目难度好像是倒着的一样.哈哈哈哈. 第一题实在是搞崩心态,这道题给我的感觉是,可以做,但事实上总是差点啥. 第二题,第三 ...

  3. 2014秋C++ 第9周项目 循环程序设计

    课程主页在http://blog.csdn.net/sxhelijian/article/details/39152703.课程资源在云学堂"贺老师课堂"同步展示,使用的帐号请到课 ...

  4. 2014秋C++第5周项目1參考-见识刚開始学习的人常见错误

    课程主页在http://blog.csdn.net/sxhelijian/article/details/39152703,实践要求见http://blog.csdn.net/sxhelijian/a ...

  5. 2014秋C++ 第7周项目 数据类型和表达式

    课程主页在http://blog.csdn.net/sxhelijian/article/details/39152703,课程资源在云学堂"贺老师课堂"同步展示,使用的帐号请到课 ...

  6. PAT 2018 秋

    A 1148 Werewolf - Simple Version 思路比较直接:模拟就行.因为需要序列号最小的两个狼人,所以以狼人为因变量进行模拟. #include <cstdio> # ...

  7. PAT 2011 秋

    A : World Cup Betting #include <cstdio> #include <iostream> #include <algorithm> u ...

  8. 【2014】【】辛星【php】【秋】【1】php构建开发环境

    **************************什么是开发环境*********************** 1.我们学习PHP,是使用它来做web用的,通俗理解,就是做站点. 2.站点的执行须要 ...

  9. 浙大PAT考试1077~1080(2014上机复试题目)

    题目地址:点击打开链接 还是太弱. . 英文太差.,, 预计要等待被虐了.. 1077 找最长的公共后缀,暴力就能够写: #include<iostream> #include<cs ...

随机推荐

  1. java多线程(待完善)

    1.小型系统 // 线程完成的任务(Runnable对象)和线程对象(Thread)之间紧密相连 class A implements Runnable{ public void run(){ // ...

  2. C语言版数据结构算法

    C语言版数据结构算法 C语言数据结构具体算法 https://pan.baidu.com/s/19oLoEVqV1I4UxW7D7SlwnQ C语言数据结构演示软件 https://pan.baidu ...

  3. Java提升四:Stream流

    1.Stream流的定义 Stream是Java中的一个接口.它的作用类似于迭代器,但其功能比迭代器强大,主要用于对数组和集合的操作. Stream中的流式思想:每一步只操作,不存储. 2.Strea ...

  4. 解析基于keras深度学习框架下yolov3的算法

    一.前言 由于前一段时间以及实现了基于keras深度学习框架下yolov3的算法,本来想趁着余热将自己的心得体会进行总结,但由于前几天有点事就没有完成计划,现在趁午休时间整理一下. 二.Keras框架 ...

  5. ubuntu18.04下安装oh-my-zsh

    安装 sudo apt-get install zsh wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/ra ...

  6. 从0开始自己配置一个vps虚拟服务器(3)

    安装数据库mysql,因为这个服务器比较烂,我只能装低版本的数据库.尝试了很多遍,终于装上去了,高版本应该没那么麻烦. 我安装了很多遍,下载的安装包,都没有安装成功. mysql各版本安装地址: (我 ...

  7. 剑指offer自学系列(四)

    题目描述: 输入一个正整数数组,把数组里面所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个,例如输入数组{3,32,321},输出的最小数字为321323 题目分析: 如果采用穷举法,把 ...

  8. Asp.net MVC中表单验证属性的使用

    用于检查是否有输入值 :RequiredFieldValidator(必须字段验证)按设定比较两个输入 :CompareValidator(比较验证) 输入是否在指定范围 :RangeValidato ...

  9. bzoj 1369: [Baltic2003]Gem

    确实是神2333333333,一开始以为是01染色sb题,然而被打脸... (蒟蒻不乱说,网上各种神犇的题解,还有图!!) #include <bits/stdc++.h> #define ...

  10. 002、将mysql用作一个简单的计算器

    SELECT PI( ), , ( ) ; 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢.