A Shortest Distance

  题意相当于一个环,找出两点间从不同方向得到的距离中的最小值。

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector> using namespace std;
vector<int> disVec;
int main()
{
int N, tmpDis;
cin >> N;
disVec.resize(N+,);
for(int i = ; i <= N; ++ i)
{
cin >> tmpDis;
disVec[i] = disVec[i-] + tmpDis;
}
cin >> disVec[];
int M, tmpSt, tmpEnd;
cin >> M;
for(int i = ; i < M; ++ i)
{
cin >> tmpSt >> tmpEnd;
if(tmpSt > tmpEnd)
swap(tmpSt, tmpEnd);
tmpDis = min(disVec[tmpEnd]-disVec[tmpSt], disVec[tmpSt]+disVec[]-disVec[tmpEnd]+disVec[N]);
cout << tmpDis << endl;
}
}

B Student List for Course

  课程清单,这个题目有点意思,我是通过把cin,cout 改成printf和scanf让它不超时的。

  试过用set会超时,暂时没有想到更好的方法。

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector> using namespace std;
vector<int> disVec;
vector<string> classInfo[];
int main()
{
int N, K, tmpNum, tmpClass;
string tmpStr;
cin >> N >> K;
for(int i = ; i <= N; ++ i)
{
cin >> tmpStr;scanf("%d", &tmpNum);
while(tmpNum--)
{
scanf("%d", &tmpClass);
classInfo[tmpClass].push_back(tmpStr);
}
}
for(int i = ; i <= K; ++ i)
{
vector<string> tmpVec = classInfo[i];
sort(tmpVec.begin(), tmpVec.end());
printf("%d %d\n", i, tmpVec.size());
for(auto it = tmpVec.begin(); it != tmpVec.end(); ++ it)
{
printf("%s\n", (*it).c_str());
}
}
return ;
}

C Find Coins

  因为需要两个硬币,所以可以排序后,用双指针法,从两端向中间找,因为在找到合适两个硬币前,一旦左侧硬币加右侧硬币超过了所需面值,右边这个硬币肯定是不可能满足条件的。

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector> using namespace std;
vector<int> coinVal;
int main()
{
int N, M, tmpVal;
cin >> N >> M;
coinVal.resize(N);
for(int i = ; i < N; ++ i)
cin >> coinVal[i];
int tmpLast = N-;
sort(coinVal.begin(), coinVal.end());
for(int i = ; i < tmpLast; ++ i)
{
while(coinVal[i] + coinVal[tmpLast] > M)
tmpLast --;
if(tmpLast != i && coinVal[i] + coinVal[tmpLast] == M)
{
cout << coinVal[i] << " " << coinVal[tmpLast];
return ;
}
}
cout << "No Solution";
return ;
}

D Counting Ones

  这个题目需要先利用数学知识找一下规律,会发现每一位产生的1的个数是有规律的,见代码while循环部分。

  (其中numArray[i]是第i位数值,multBase是0-9、0-99、0-999...中包含1的个数,digitBase是0,10,100,1000...)

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector> using namespace std;
int charToNum(char c)
{
return c-'';
}
int n;
char numStr[];
int numArray[];
int len;
int numDeal(int tmpN)
{
int tmpNum = ;
int digitBase = ;
int multBase = ;
while(tmpN >= )
{
if(numArray[tmpN] == )
{
tmpNum += numArray[tmpN] * multBase + n%digitBase+;
}
else if(numArray[tmpN] > )
{
tmpNum += numArray[tmpN] * multBase + digitBase;
}
multBase = * multBase + digitBase;
digitBase *= ;
tmpN--;
}
return tmpNum;
}
int main()
{ cin >> n;
sprintf(numStr, "%d", n);
len = strlen(numStr);
for(int i = ; i < len; ++ i)
numArray[i] = charToNum(numStr[i]);
int num = numDeal(len-);
cout << num;
return ;
}

PAT 2012 冬的更多相关文章

  1. Windows server 2012 添加中文语言包(英文转为中文)(离线)

    Windows server 2012 添加中文语言包(英文转为中文)(离线) 相关资料: 公司环境:亚马孙aws虚拟机 英文版Windows2012 中文SQL Server2012安装包,需要安装 ...

  2. Windows Server 2012 NIC Teaming介绍及注意事项

    Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...

  3. 1.初始Windows Server 2012 R2 Hyper-V + 系统安装详细

    干啥的?现在企业服务器都是分开的,比如图片服务器,数据库服务器,redis服务器等等,或多或少一个网站都会用到多个服务器,而服务器的成本很高,要是动不动采购几十台,公司绝对吃不消的,于是虚拟化技术出来 ...

  4. 0.Win8.1,Win10,Windows Server 2012 安装 Net Framework 3.5

    后期会在博客首发更新:http://dnt.dkill.net 网站部署之~Windows Server | 本地部署:http://www.cnblogs.com/dunitian/p/482280 ...

  5. windows 2012 r2 can't find kb2919355

    问题   解决: 1.手动安装了 Windows8.1-KB2919442-x64 2.手动下载 KB2919355 更新成功     Turns out to have been a result ...

  6. Windows Server 2012 磁盘管理之 简单卷、跨区卷、带区卷、镜像卷和RAID-5卷

    今天给客户配置故障转移群集,在Windows Server 2012 R2的系统上,通过iSCSI连接上DELL的SAN存储后,在磁盘管理里面发现可以新建 简单卷.跨区卷.带区卷.镜像卷.RAID-5 ...

  7. VMware下Windows Server 2012添加新磁盘

    系统管理员在VM下新装了一台Windows Server 2012服务器,我在上面安装了SQL Server 2014 Standard版数据库,安装之初,只分配了一个C盘,我想在这台服务器上添加了三 ...

  8. 在Windows Server 2012中如何快速开关桌面上经典的“计算机、我的文档”等通用图标

    我们都知道,在Windows Server 2012系列的服务器版本中都已经引入了Modern的现代界面作为默认的用户交互界面,同时满足视觉一致化,新版的服务器管理程序也做成了扁平化.因此传统的计算机 ...

  9. 《转载》PAT 习题

    博客出处:http://blog.csdn.net/zhoufenqin/article/details/50497791 题目出处:https://www.patest.cn/contests/pa ...

随机推荐

  1. 小程序通过web-view实现与h5页面之间的交互

    在小程序端使用web-view内嵌网页,通过 src 携带参数,通过 @message 接收h5传回的数据 <template> <view> <web-view :sr ...

  2. web.xml CharacterEncodingFilter

    <!-- SpingMVC字符集过滤器 --> <filter> <filter-name>characterEncodingFilter</filter-n ...

  3. 刷题21. Merge Two Sorted Lists

    一.题目说明 这个题目是21. Merge Two Sorted Lists,归并2个已排序的列表.难度是Easy! 二.我的解答 既然是简单的题目,应该一次搞定.确实1次就搞定了,但是性能太差: R ...

  4. 洛谷 P3801 红色的幻想乡

    题目背景 蕾米莉亚的红雾异变失败后,很不甘心. 题目描述 经过上次失败后,蕾米莉亚决定再次发动红雾异变,但为了防止被灵梦退治,她决定将红雾以奇怪的阵势释放. 我们将幻想乡看做是一个n*m的方格地区,一 ...

  5. 009、MySQL取当前时间Unix时间戳,取今天Unix时间戳

    #取Unix时间戳 SELECT unix_timestamp( ) ; #取今天时间戳 SELECT unix_timestamp( curdate( ) ); 显示如下: 不忘初心,如果您认为这篇 ...

  6. ①spring简介以及环境搭建(一)

    注*(IOC:控制反转.AOP:面向切面编程) spring官网:http://spring.io/ spring简介: spring是一个开源框架 spring为简化企业级应用开发而生,使用Spri ...

  7. B. RGB plants

    B. RGB plants time limit per test 2.0 s memory limit per test 64 MB input standard input output stan ...

  8. Linux学习《第四章shell脚本练习一》随堂练习(重要)

  9. HDU - 6000 Wash(优先队列+贪心)

    题意:已知有L件衣服,M个洗衣机,N个烘干机,已知每个机器的工作时间,且每个机器只能同时处理一件衣服,问洗烘完所有衣服所需的最短时间. 分析: 1.优先队列处理出每件衣服最早的洗完时间. 2.优先队列 ...

  10. 【pwnable.kr】blackjack

    又一道pwnable nc pwnable.kr 9009 读题找到源代码在:http://cboard.cprogramming.com/c-programming/114023-simple-bl ...