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. arm linux 移植支持 HP打印机

    背景 由于业务需要,需要hi3531d主板上加入对于HP打印机的支持. 通过与产品经理,技术主管的沟通:通用支持是不现实的,只要求彩色打印,先不考虑打印机的价格,只要支持一款打印机即可. 注意: Li ...

  2. delphi对ZIP解压

    Delphi 对GZIP解压 作者:admin 来源:未知 日期:2010/5/9 13:08:46 人气:获取失败 标签: QQ空间新浪微博腾讯微博腾讯朋友QQ收藏百度空间百度贴吧更多0 呵呵,终于 ...

  3. CSS - 控制最后边框的隐藏或设置为none

    div{       width: 20%;       border-left: 1px solid $border-color;       &:nth-child(5n+1){      ...

  4. liunx mysql 5.7 二进制安装

    liunx 5.6版本 本人安装次数不下20次,基本上按照正常的操作流程不会出现什么问题,一切顺利. 今天开发新项目需要按照mysql 5.7 版本.mysql 5.7版本和mysql 5.6版本变化 ...

  5. PHP中strlen和mb_strlen函数的使用方式的不同

    (1)strlen  获取字符串长度 (2)mb_strlen  使用方法:   int mb_strlen ( string $str [, string $encoding ] )返回给定的字符串 ...

  6. IQueryable 转DataTable

    public static DataTable CopyToDataTable<T>(IEnumerable<T> array) { var ret = new DataTab ...

  7. springboot创建bean

    springboot创建bean的方式有两种: 1.直接类上加注解@Component@Controller@Service ... 2.使用@Bean注解配合@Configuration注解 区别是 ...

  8. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-off

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  9. Problem B: Bulbs

    Problem B: Bulbs Greg has an m×n grid of Sweet Lightbulbs of Pure Coolness he would like to turn on. ...

  10. J. Cola

    J. Cola time limit per test 4.0 s memory limit per test 64 MB input standard input output standard o ...