pat1041-1050
没想到半天就做完了10题 = =,这几题太简单了,基本10分钟一题
1041
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const int INF = 0x3f3f3f3f;
#define MP(x, y) make_pair(x, y)
int A[N];
map<int, int> mp;
int main() {
int n;
while(~scanf("%d", &n)) {
mp.clear();
for(int i = 1; i <= n; ++i) scanf("%d", &A[i]), mp[A[i]] ++;
int fl = 0;
for(int i = 1; i <= n; ++i) {
if(mp[A[i]] == 1) {
printf("%d\n", A[i]); fl = 1;
break;
}
}
if(!fl) printf("None\n");
}
return 0;
}
1042
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 4e4+5;
const int INF = 0x3f3f3f3f;
#define MP(x, y) make_pair(x, y)
int card[2][N]; int fl;
void put(int x) {
int t1 = (x-1)/13;
int t2 = (x-1)%13;
t2 ++;
if(t1 == 4) printf("J%d", t2);
else if(t1 == 3) printf("D%d", t2);
else if(t1 == 2) printf("C%d", t2);
else if(t1 == 1) printf("H%d", t2);
else printf("S%d", t2);
}
int Swap[60];
int main() {
int K;
while(~scanf("%d", &K)) {
fl = 0;
for(int i = 1; i <= 54; ++i) card[fl][i] = i;
for(int i = 1; i <= 54; ++i) scanf("%d", &Swap[i]);
for(int i = 0; i < K; ++i) {
for(int j = 1; j <= 54; ++j) {
card[fl^1][Swap[j]] = card[fl][j];
}
fl ^= 1;
}
for(int i = 1; i <= 54; ++i) {
if(i != 1) printf(" ");
put(card[fl][i]);
}
printf("\n");
}
return 0;
}
1043 这题还是花了一点时间。这是一个反证思想,虽然你按照这个序列插入的树,其他序列可能插入也是这样,但是你反过来验证一下不就行了= =
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e3+5;
const int INF = 0x3f3f3f3f;
#define MP(x, y) make_pair(x, y)
int n;
int A[N];
int lef[N], righ[N];
int root;
void find(int x, int id) {
if(A[x] <= A[id]) {
if(righ[x] == 0) righ[x] = id;
else find(righ[x], id);
}else {
if(lef[x] == 0) lef[x] = id;
else find(lef[x], id);
}
}
void _find(int x, int id) {
if(A[x] > A[id]) {
if(righ[x] == 0) righ[x] = id;
else _find(righ[x], id);
}else {
if(lef[x] == 0) lef[x] = id;
else _find(lef[x], id);
}
}
int output[N]; int cnt = 0;
void preorder(int x) {
++cnt; output[cnt] = x;
if(lef[x]) preorder(lef[x]);
if(righ[x]) preorder(righ[x]);
}
void postorder(int x) {
if(lef[x]) postorder(lef[x]);
if(righ[x]) postorder(righ[x]);
++cnt; output[cnt] = x;
}
int main() {
while(~scanf("%d", &n)) {
memset(lef, 0, sizeof(lef));
memset(righ, 0, sizeof(righ));
for(int i = 1; i <= n; ++i) {
scanf("%d", &A[i]);
}
root = 1;
for(int i = 2; i <= n; ++i) {
find(root, i);
}
cnt = 0;
preorder(root);
int flag = 1;
for(int i = 1; i <= n; ++i) {
if(output[i] != i) {
flag = 0; break;
}
}
if(flag) {
cnt = 0;
printf("YES\n");
postorder(root);
for(int i = 1; i <= n; ++i) {
if(i != 1) printf(" ");
printf("%d", A[output[i]]);
}
printf("\n");
continue;
}
memset(lef, 0, sizeof(lef));
memset(righ, 0, sizeof(righ));
root = 1;
for(int i = 2; i <= n; ++i) {
_find(root, i);
}
cnt = 0;
preorder(root);
flag = 1;
for(int i = 1; i <= n; ++i) {
if(output[i] != i) {
flag = 0; break;
}
}
if(flag) {
cnt = 0;
printf("YES\n");
postorder(root);
for(int i = 1; i <= n; ++i) {
if(i != 1) printf(" ");
printf("%d", A[output[i]]);
}
printf("\n");
}else printf("NO\n");
}
return 0;
}
1044 二分一下就行,比较简单
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+5;
typedef long long ll;
int value[N];
int suf[N];
int main() {
int n, m;
while(~scanf("%d %d", &n, &m)) {
int fl = 0;
for(int i = 1; i <= n; ++i) {
scanf("%d", &value[i]);
// if(value[i] <= 0) while(1);
}
suf[0] = 0;
int pre = 0;
int minn = INF;
for(int i = 1; i <= n; ++i) {
pre += value[i];
suf[i] = pre;
// printf("%d ", suf[i]);
// if(i == 1) continue;
int id = lower_bound(suf, suf+i, pre-m) - suf;
if(suf[id] == pre-m) {
printf("%d-%d\n", id+1, i);
fl = 1;
}else {
if(id == 0) continue;
int tt = suf[i] - suf[id-1];
if(tt > m) minn = min(minn, tt);
}
}
if(!fl) {
pre = 0;
for(int i = 1; i <= n; ++i) {
pre += value[i];
suf[i] = pre;
// if(i == 1) continue;
int id = lower_bound(suf, suf+i, pre - minn) - suf;
if(suf[id] == pre - minn) {
printf("%d-%d\n", id+1, i);
// fl = 1;
}
}
}
}
return 0;
}
1045 这题dp,每次讨论一个点,找到此时,小于等于该物品喜欢程度为结尾的物品的最大值,当然我用树状数组加速了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+5;
typedef long long ll;
int fav[205];
int fav_[205];
int stripe[10005];
int tree[205];
int n, m, len;
void add(int pos, int num) {
for(int i = pos; i <= m; i += i&-i) {
tree[i] = max(tree[i], num);
}
}
int sum(int pos) {
int ans = 0;
for(int i = pos; i; i -= i&-i) {
ans = max(ans, tree[i]);
}
return ans;
}
int main() {
while(~scanf("%d", &n)) {
memset(fav_, 0, sizeof(fav_));
memset(tree, 0, sizeof(tree));
scanf("%d", &m);
for(int i = 1; i <= m; ++i) {
scanf("%d", &fav[i]);
fav_[fav[i]] = i;
}
scanf("%d", &len);
for(int i = 1; i <= len; ++i) {
scanf("%d", &stripe[i]);
}
for(int i = 1; i <= len; ++i) {
if(fav_[stripe[i]] == 0) continue;
int id = fav_[stripe[i]];
int tt = sum(id)+1;
add(id, tt);
}
printf("%d\n", sum(m));
}
return 0;
}
1046
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+5;
typedef long long ll;
int d[N];
ll suf[N];
int main() {
int n, m;
while(~scanf("%d", &n)) {
suf[0] = 0;
for(int i = 1; i <= n; ++i) {
scanf("%d", &d[i]);
suf[i] = suf[i-1] + d[i];
}
scanf("%d", &m);
for(int i = 1; i <= m; ++i) {
int a, b; scanf("%d %d", &a, &b);
if(a > b) swap(a, b);
ll tmp = suf[b-1] - suf[a-1];
ll ans = min(tmp, suf[n] - tmp);
printf("%lld\n", ans);
}
}
return 0;
}
1047 还是先将字符串处理成了数字,这样更快
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+5;
typedef long long ll;
int change(char *a) {
int ans = 0;
for(int i = 0; i < 3; ++i) {
ans = ans*100 + a[i]-'A';
}
ans = ans*100 + a[3]-'0'+30;
return ans;
}
void put(int x) {
printf("%c%c%c%c\n", x/1000000+'A', (x%1000000)/10000+'A', (x%10000)/100+'A', (x%100-30)+'0' );
}
vector<int> course[2505];
int main() {
int n, k;
while(~scanf("%d %d", &n, &k)) {
for(int i = 1; i <= k; ++i) course[i].clear();
for(int i = 0; i < n; ++i) {
char s[10]; int a;
scanf("%s %d", s, &a);
int id = change(s);
for(int j = 0; j < a; ++j) {
int b; scanf("%d", &b);
course[b].push_back(id);
}
}
for(int i = 1; i <= k; ++i) {
printf("%d %d\n", i, course[i].size());
sort(course[i].begin(), course[i].end());
for(int j = 0; j < course[i].size(); ++j) {
put(course[i][j]);
}
}
}
return 0;
}
1048
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+5;
typedef long long ll;
int coin[N];
map<int, int> mp;
int main() {
int n, m;
while(~scanf("%d %d", &n, &m)) {
mp.clear();
for(int i = 1; i <= n; ++i) {
scanf("%d", &coin[i]);
mp[coin[i]] ++;
}
sort(coin+1, coin+n+1);
int fl = 0;
for(int i = 1; i <= n; ++i) {
int re = m - coin[i];
if(re == coin[i]) {
if(mp[re] >= 2) {
printf("%d %d\n", re, re); fl = 1;
break;
}
}else {
if(mp.find(re) != mp.end()) {
printf("%d %d\n", coin[i], re); fl = 1;
break;
}
}
}
if(!fl) printf("No Solution\n");
}
return 0;
}
1049 这题还是要想下,先预处理 0-999999 那么一个大于1e6的数就可以拆分成前五位,后五位来做就行啦
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e6;
typedef long long ll;
ll num[N];
int cal(int x) {
int ans = 0;
while(x) {
int tt = x%10;
if(tt == 1) ans ++;
x /= 10;
}
return ans;
}
int main() {
num[0] = 0;
for(int i = 1; i < N; ++i) {
num[i] = num[i-1] + cal(i);
}
int x;
while(~scanf("%d", &x)) {
if(x < 1e6) printf("%lld\n", num[x]);
else {
int t1 = x % 1000000; int t2 = x / 1000000;
ll ans = (num[t2]-cal(t2)) * 1e6 + 1ll*cal(t2)*(t1+1) + num[999999] * t2 + num[t1];
printf("%lld\n", ans);
}
}
return 0;
}
1050
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e4+5;
typedef long long ll;
char a[N], b[N];
int has[200];
int main() {
memset(has, 0, sizeof(has));
gets(a); gets(b);
for(int i = 0; b[i]; ++i) {
has[b[i]] ++;
}
for(int i = 0; a[i]; ++i) {
if(!has[a[i]]) printf("%c", a[i]);
}
printf("\n");
return 0;
}
pat1041-1050的更多相关文章
- [Q&A] MySQL Error 1050(42S01): Table already exist
[环境说明] 1:MySQL Server 5.5 2:MyEclipse 2014 3:JDK 1.7 造成该问题的可能原因: 1:用 Java 读取 SQL 文件,并执行其中的 sql 语句,但是 ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- magento -- 解决magento错误:ERROR: Base table or view already exists: 1050 Table ... already exists
相信有更新magento或者,备份转移magento站点的时候可能会碰到类似这样的错误提示: Base table or view already exists: 1050 Table ... alr ...
- --hdu 1050 Moving Tables(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...
- hdu 1050 Moving Tables 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...
- NBOJv2 1050 Just Go(线段树/树状数组区间更新单点查询)
Problem 1050: Just Go Time Limits: 3000 MS Memory Limits: 65536 KB 64-bit interger IO format: % ...
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- BZOJ 1050 旅行comf(枚举最小边-并查集)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1050 题意:给出一个带权图.求一条s到t的路径使得这条路径上最大最小边的比值最小? 思路 ...
- hiho #1050 : 树中的最长路 树的直径
#1050 : 树中的最长路 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中, ...
- 51nod 1050 循环数组最大子段和
题目链接:51nod 1050 循环数组最大子段和 #include<stdio.h> #include<algorithm> using namespace std; ; l ...
随机推荐
- 前端-Useful Js Plugins
Validform.min.js:提供对表单的验证.提交等功能,具体可查阅相关文档,@Validform 示例: $("#id").Validform() ; WdatePicke ...
- Android Studio,使用外部模拟器作为生成app调试的模拟器
本文作为一个原理探究的存在. 1.作者观察发现,逍遥和夜神模拟器自身,都是有一个adb.exe和nox_adb.exe存在的,这个东西是干嘛用的呢. 应该是和本身模拟器进行通信的,我测试可以通过他们自 ...
- 测试人员如何使用Git部署测试环境
Git是分布式的版本控制系统. 作为一名Git的小白使用者,一开始接触很懵逼,因为总担心自己一不小心误操作影响代码仓库的代码,网络上关于Git的使用多从开发的角度,很少有人从测试的角度来介绍Git的使 ...
- 浅显总结ASCII Unicode UTF-8的区别
如果觉得此地排版不好,欢迎访问我的博客 浅显总结ASCII Unicode UTF-8的区别 制作表单时,为了追求更好的用户交互体验,常常会有提示性的内容,比如提醒用户字符的限制.由于英文,中文字符的 ...
- IDEA的Maven依赖如何引入到External Libraries中
现象 在Apollo项目中,遇到了一个问题.当在Module的pom.xml中引入依赖: <dependency> <groupId>com.ctrip.framework.a ...
- Install Centrifugo and quick start
Install Centrifugo and quick start Go is a perfect language - it gives developers an opportunity to ...
- CentOS安装JDK 8
准备工作 首先,更新包: yum update 检查服务器上是否已安装旧版本的Java: java -version 如果有旧版本的Java则移除: yum remove java-1.6.0-ope ...
- maven项目打包的时候,*Mapper.xml 文件会打不不进去解决办法
打包的时候,不同版本的 Eclipse 还有IDEA 会有打包打不进去Mapper.xml 文件,这个时候要加如下代码, 在<build> 标签内加入即可 <resources> ...
- 对于文件File类型中的目录分隔符
当我们在使用File f=new File(path); 对于这个path来说是一个很痛苦的事情,在不同的系统上面的分隔符号是不一样的 在windows下面的话是一个"\"而在un ...
- Java中Dom解析xml文档
xml文档 <?xml version="1.0" encoding="UTF-8"?> <bookstore> <book id ...