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. 浅谈Spring 5的响应式编程

    这篇使用Spring 5进行响应式编程的入门文章展示了你现在可以使用的一些新的non-blocking, asynchronous.感谢优锐课老师给予的指导! 近年来,由于响应式编程能够以声明性的方式 ...

  2. PHPExcel方法总结

    下面是总结的几个使用方法include 'PHPExcel.php';include 'PHPExcel/Writer/Excel2007.php';//或者include 'PHPExcel/Wri ...

  3. 1 初识JVM

  4. Django(九)模型:dj查询数据库的函数(方法)

    一.查询函数 通过模型类.objects属性可以调用如下函数,实现对模型类对应的数据表的查询. 函数表 函数名 功能 返回值 说明 get 返回表中满足条件的一条且只能有一条数据. 返回值是一个模型类 ...

  5. Exchange 2003 限制用户向外网发送邮件

    在企业系统中,邮件系统起着举足轻重的作用.同时为了符合企业的安全性策略,在Exchange 2003 中,常常需要限制某个用户或组向外网发送邮件,只允许此邮件在内部收发.下面我们以实验的方式来分析在E ...

  6. python 鞍点

    # 鞍点: 所在行的最大值,所在列的最小值 import random A = [[random.randint(1,100) for j in range(5)]for i in range(5)] ...

  7. ORIGIN(起源属性)路由起源骗术

    ORIGIN(起源属性)配置: ①:抓取感兴趣流量——prefix.access ②:创建route-map 流量地图——permit 10 ③:匹配感兴趣流量——match ④:设置起源属性——se ...

  8. JavaScript中的面向对象及有关应用

    面向对象(OOP:Object Oriented Programming)  面向对象的概念 面向对象是一种程序设计思想,将数据和处理数据的程序封装到对象中. 特性:抽象.继承.封装.多态. 优点:提 ...

  9. Python 爬虫是什么

    作为程序员,相信大家对“爬虫”这个词并不陌生,身边常常会有人提这个词,在不了解它的人眼中,会觉得这个技术很高端很神秘.不用着急,我们的爬虫系列就是带你去揭开它的神秘面纱,探寻它真实的面目. ! 爬虫是 ...

  10. ActiveMQ消息队列和SignalR之日志实时监控及警报小实例

    主要技术: log4net-生成日志. ActiveMQ-生成日志的时候发送消息,并实时监控日志. SignalR-将ActiveMQ监控的日志实时显示到浏览器上,而不用刷新浏览器. 小实例介绍: 左 ...