pat1031-1040
1031
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e6+5;
const int M = 3e5+5;
char s[85];
int n1,n2,n3;
char mp[100][100];
int main() {
while(~scanf("%s", s)) {
memset(mp, 0, sizeof(mp));
int len = strlen(s);
int t1 = len-2;
int t2 = t1/3; int t3 = t1%3;
n1 = n2 = n3 = t2;
if(t3 == 1) n2 ++;
else if(t3 == 2) n1 ++, n3 ++;
// printf("%d %d %d\n", n1, n2, n3);
int x = 1, y = 1; int cn = 0;
for(int i = 1; i <= n1+1; ++i) {
mp[x][y] = s[cn++];
x ++;
}
x--; y++;
for(int i = 1; i <= n2+1; ++i) {
mp[x][y] = s[cn++];
y ++;
}
y--; x--;
for(int i = 1; i <= n3; ++i) {
mp[x][y] = s[cn++];
x --;
}
for(int i = 1; i <= n1+1; ++i) {
for(int j = 1; j <= n2+2; ++j) {
if(!mp[i][j]) printf(" ");
else printf("%c", mp[i][j]);
}
printf("\n");
}
}
return 0;
}
1032 这题如果是 字符相等不一定是后缀,必须指针相等
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
using namespace std;
const int N = 1e6+5;
char Data[N]; int nx[N];
vector<char> ans[2];
vector<int> indx[2];
void dfs(int x, int tag) {
if(x == -1) return;
ans[tag].push_back(Data[x]);
indx[tag].push_back(x);
dfs(nx[x], tag);
}
int main() {
int s, t, n;
while(~scanf("%d %d %d", &s, &t, &n)) {
ans[0].clear(); ans[1].clear();
indx[0].clear(); indx[1].clear();
for(int i = 1; i <= n; ++i) {
int a; char b; int c;
scanf("%d %c %d", &a, &b, &c);
Data[a] = b; nx[a] = c;
}
dfs(s, 0);
dfs(t, 1);
int Ans = -1;
for(int i = ans[0].size()-1, j = ans[1].size()-1; i >= 0 && j >= 0; --j, --i) {
if(indx[0][i] != indx[1][j]) {
break;
}else {
Ans = indx[0][i];
}
}
if(Ans == -1) printf("-1\n");
else printf("%05d\n", Ans);
}
return 0;
}
1033这题有人水的吧!一点不好做。这个贪心我是想了一晚上,具体看代码吧,我无力吐槽,x是上次加油的点,premm和mm是这次我上次加油的点会加多少油的区间
#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 = 505;
typedef long long ll;
struct Node{
double p; int d;
}E[N];
int cmp(Node a, Node b) {
return a.d < b.d;
}
int main() {
int cap, dis, v, n;
while(~scanf("%d %d %d %d", &cap, &dis, &v, &n)) {
for(int i = 1; i <= n; ++i) {
scanf("%lf %d", &E[i].p, &E[i].d);
}
E[0].p = INF; E[0].d = 0;
sort(E+1, E+n+1, cmp);
if(E[1].d != 0) {
printf("The maximum travel distance = 0.00\n");
continue;
}
int x = 0;
int premm = 0;
int mm = 0; double ans = 0;
while(1) {
int fr = x+1, to;
// printf("%d %d %d %.2f\n", x, premm, mm, ans);
for(int i = x+1; i <= n; ++i) {
if(E[i].d <= mm) {
to = i;
}else break;
}
double minn = INF*1.0; int minp = 0;
for(int i = fr; i <= to; ++i) {
if(E[i].p < E[x].p) {
minp = i; minn = E[i].p;
break;
}
}
// printf("%d to %d: %d\n", fr, to, minp);
if(!minp) {
for(int i = fr; i <= to; ++i) {
if(minn > E[i].p) {
minp = i; minn = E[i].p;
}
}
// printf("chpos: %d\n", minp);
if(mm >= dis) {
ans += (dis - premm)*1.0 /v *E[x].p;
break;
}else if(!minp) break;
else {
// printf("hh %d %d\n", E[minp].d, E[x].d);
ans += (mm - premm)*1.0 /v * E[x].p;
premm = mm;
mm += E[minp].d -E[x].d;
x = minp;
// printf("%d\n", mm);
}
}else {
ans += (E[minp].d - premm)*1.0 /v *E[x].p;
premm = E[minp].d;
x = minp;
mm = E[minp].d + cap * v;
}
}
if(mm < dis) printf("The maximum travel distance = %.2f\n", mm*1.0 );
else printf("%.2f\n", ans);
}
return 0;
}
1034 并查集一下,无法理解正确率和上一题一样,我觉得我做到现在最难的是1033
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
using namespace std;
const int N = 2e3+5;
#define mp(A,B) make_pair(A,B)
map<string, int> mp;
char name[N][10];
int tot = 0;
int pre[N];
int fa(int x) {
return pre[x] == x? x: pre[x] = fa(pre[x]);
}
int cnt[N];
vector<int> gang[N];
struct Node{
char nam[5];
int per;
}E[N];
int alltot;
int cmp(Node a,Node b) {
for(int i = 0; i < 3; ++i) {
if(a.nam[i] != b.nam[i]) {
return a.nam[i] < b.nam[i];
}
}
}
int main() {
int n, k;
while(~scanf("%d %d", &n, &k)) {
alltot = 0;
memset(cnt, 0, sizeof(cnt));
tot = 0; mp.clear();
for(int i = 1; i <= 2*n; ++i) pre[i] = i;
for(int i = 1; i <= 2*n; ++i) gang[i].clear();
for(int i = 0; i < n; ++i) {
char a[10]; char b[10]; int c;
scanf("%s %s %d", a, b, &c);
if(mp.find(a) == mp.end()) {
tot ++; mp[a] = tot;
for(int j = 0; j < 3; ++j) name[tot][j] = a[j];
}
if(mp.find(b) == mp.end()) {
tot ++; mp[b] = tot;
for(int j = 0; j < 3; ++j) name[tot][j] = b[j];
}
int a1 = mp[a]; int b1 = mp[b];
int t1 = fa(a1); int t2 = fa(b1);
if(t1 != t2) pre[t1] = t2;
cnt[a1] += c; cnt[b1] += c;
}
for(int i = 1; i <= tot; ++i) {
gang[fa(i)].push_back(i);
}
for(int i = 1; i <= tot; ++i) {
if(gang[i].size() > 2) {
int maxx = -1; int maxp;
int all = 0;
for(int j = 0; j < gang[i].size(); ++j) {
if(maxx < cnt[gang[i][j]] ) {
maxx = cnt[gang[i][j]]; maxp = j;
}
all += cnt[gang[i][j]];
}
all /= 2;
if(all <= k) continue;
alltot ++;
E[alltot].per = gang[i].size();
for(int j = 0; j < 3; ++j) {
E[alltot].nam[j] = name[gang[i][maxp]][j];
}
}
}
if(alltot == 0) {
printf("0\n"); continue;
}
sort(E+1, E+alltot+1, cmp);
printf("%d\n", alltot);
for(int i = 1; i <= alltot; ++i) {
for(int j = 0; j < 3; ++j) printf("%c", E[i].nam[j]); printf(" ");
printf("%d\n", E[i].per);
}
}
return 0;
}
1035 there is /are 注意下
#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 = 505;
const int INF = 0x3f3f3f3f;
#define MP(x, y) make_pair(x, y)
vector<pair<string, string> > vc;
int main() {
int n;
while(~scanf("%d", &n)) {
vc.clear();
for(int i = 0; i < n; ++i) {
char a[20]; char b[20];
scanf("%s %s", a, b);
int len = strlen(b);
int fl = 0;
for(int j = 0; j < len; ++j) {
if(b[j] == '1') {
fl = 1; b[j] = '@';
}else if(b[j] == '0') {
fl = 1; b[j] = '%';
}else if(b[j] == 'l') {
fl = 1; b[j] = 'L';
}else if(b[j] == 'O') {
fl = 1; b[j] = 'o';
}
}
if(fl) vc.push_back(MP(a, b));
}
if(vc.size() == 0) {
if(n == 1) printf("There is %d account and no account is modified\n", n);
else printf("There are %d accounts and no account is modified\n", n);
}else {
printf("%d\n", vc.size());
for(int i = 0; i < vc.size(); ++i) {
printf("%s %s\n", vc[i].first.c_str(), vc[i].second.c_str());
}
}
}
return 0;
}
1036
#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)
struct Node{
char name[20];
char sex;
char Id[20];
int grade;
}E[N];
int main() {
int n;
while(~scanf("%d", &n)) {
int minn = INF; int minp = 0;
int maxn = -1; int maxp = 0;
for(int i = 1; i <= n; ++i) {
scanf("%s %c %s %d", E[i].name, &E[i].sex, E[i].Id, &E[i].grade);
if(E[i].sex == 'M') {
if(E[i].grade < minn) {
minn = E[i].grade; minp = i;
}
}else {
if(E[i].grade > maxn) {
maxn = E[i].grade; maxp = i;
}
}
}
if(!maxp) printf("Absent\n");
else printf("%s %s\n", E[maxp].name, E[maxp].Id);
if(!minp) printf("Absent\n");
else printf("%s %s\n", E[minp].name, E[minp].Id);
if(!minp || !maxp) printf("NA\n");
else printf("%d\n", E[maxp].grade - E[minp].grade);
}
return 0;
}
1037
#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];
int B[N];
int main() {
int n, p;
while(~scanf("%d", &n)) {
for(int i = 1; i <= n; ++i) scanf("%d", &A[i]);
scanf("%d", &p);
for(int i = 1; i <= n; ++i) scanf("%d", &B[i]);
sort(A+1, A+n+1);
sort(B+1, B+n+1);
ll ans = 0;
for(int i = 1; i <= n; ++i) {
ll tmp = 1ll *A[i] *B[i];
if(tmp > 0) ans += tmp;
}
printf("%lld\n", ans);
}
return 0;
}
1038 我瞎想的排序方法,不过觉得很有道理
#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)
struct Node{
char num[10];
}s[N];
int cmp(Node A, Node B) {
char a[20]; char b[20];
int cnt;
int l1 = strlen(A.num); int l2 = strlen(B.num);
cnt = 0;
for(int i = 0; i < l1; ++i) a[cnt++] = A.num[i];
for(int i = 0; i < l2; ++i) a[cnt++] = B.num[i];
cnt = 0;
for(int i = 0; i < l2; ++i) b[cnt++] = B.num[i];
for(int i = 0; i < l1; ++i) b[cnt++] = A.num[i];
int l = strlen(a);
for(int i = 0; i < l; ++i) {
if(a[i] != b[i])
return a[i] < b[i];
}
return 1;
}
int main() {
int n;
while(~scanf("%d", &n)) {
for(int i = 1; i <= n; ++i) {
scanf("%s", s[i].num);
}
sort(s+1, s+n+1, cmp);
int fl = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 0; s[i].num[j]; ++j) {
if(s[i].num[j] != '0') {
fl = 1; printf("%c", s[i].num[j]);
}else if(fl) {
printf("0");
}
}
}
if(!fl) printf("0");
printf("\n");
}
return 0;
}
1039 加了一点小优化卡过去的,有大神能进100ms吗,我才170,
#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 n, k;
set<int> stu[N];
char nam[N][20];
map<int, int> ask;
vector<int> vc[3000];
set<int> ::iterator it;
int change(char a[]) {
// for(int i = 0; i < 4; ++i) printf("%c", a[i]); printf("\n");
int tt = 0;
for(int i = 0; i < 3; ++i) {
tt = tt*100+ a[i]-'A';
}
tt = tt*100 + 30+a[3]-'0';
return tt;
}
int main() {
// printf("%d\n", change("ZZZ9"));
while(~scanf("%d %d", &n, &k)) {
// ask.clear();
// for(int i = 1; i <= k; ++i) vc[i].clear();
// for(int i = 1; i <= n; ++i) stu[i].clear();
for(int i = 1; i <= k; ++i) {
int a,b; scanf("%d %d", &a, &b);
char s[10];
for(int j = 0; j < b; ++j) {
scanf("%s" , s);
vc[a].push_back(change(s));
}
}
for(int i = 1; i <= n; ++i) {
scanf("%s", nam[i]);
ask[change(nam[i])] = i;
}
for(int i = 1; i <= k; ++i) {
for(int j = 0; j < vc[i].size(); ++j) {
int tt = vc[i][j];
if(ask.find(tt) != ask.end()) {
stu[ask[tt]].insert(i);
}
}
}
for(int i = 1; i <= n; ++i) {
printf("%s %lu", nam[i], stu[i].size());
// sort(stu[i].begin(), stu[i].end());
for(it = stu[i].begin(); it != stu[i].end(); ++it) {
printf(" %d", *it);
// int tt = stu[i][j];
// printf(" %d", tt);
}
printf("\n");
}
}
return 0;
}
1040 manacher 搞一搞
#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 = 1e4+5;
const int INF = 0x3f3f3f3f;
#define MP(x, y) make_pair(x, y)
char s[N];
char Ma[N*2];
int Mp[N*2];
void Manacher() {
int len = strlen(s);
int l = 0;
Ma[l++] = '$';
Ma[l++] = '#';
for(int i = 0; i < len; ++i) {
Ma[l++] = s[i];
Ma[l++] = '#';
}
Ma[l] = 0;
int mx = 0, id = 0;
for(int i = 0; i < l; ++i) {
Mp[i] = mx>i? min(Mp[2*id-1], mx-i) : 1;
while(Ma[i+Mp[i]] == Ma[i-Mp[i]]) Mp[i] ++;
if(i + Mp[i] > mx) {
mx = i + Mp[i];
id = i;
}
}
}
int main() {
gets(s);
int len = strlen(s);
Manacher();
int ans = 0;
for(int i = 0; i < 2*len+2; ++i) {
ans = max(ans, Mp[i]-1);
}
printf("%d\n", ans);
return 0;
}
pat1031-1040的更多相关文章
- PAT (Basic Level) Practise 1040 有几个PAT(DP)
1040. 有几个PAT(25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 字符串APPAPT中包含了两个单 ...
- 打开mysql时,提示 1040,Too many connections
打开mysql时,提示 1040,Too many connections,这样就无法打开数据库,看不了表里边的内容了. 出现这个问题的原因是,同时对数据库的连接数过大,mysql默认的最大连接数是1 ...
- 51nod 1040最大公约数和(欧拉函数)
1040 最大公约数之和 题目来源: rihkddd 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 给出一个n,求1-n这n个数,同n的最大公约数 ...
- 【BZOJ】1040: [ZJOI2008]骑士(环套树dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1040 简直不能再神的题orz. 蒟蒻即使蒟蒻,完全不会. 一开始看到数据n<=1000000就 ...
- 【BZOJ】【1040】【ZJOI2008】骑士
树形DP/基环树DP 我掉坑掉了好多…… 这题图比较特殊,每个连通块都是一棵基环树(我一开始以为图是连通的了……sigh,我说为什么网上的题解都要累加ans……),那么对于一棵基环树,我们先dfs找到 ...
- hihoCoder 1040 矩形判断(计算几何)
http://hihocoder.com/problemset/problem/1040 首先判断四条线段是否相交,给出八个点,如果有一些点重合,并且不同坐标的点只有4个的话,表示可以构成四边形. 然 ...
- BZOJ 1040: [ZJOI2008]骑士 基环加外向树
1040: [ZJOI2008]骑士 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1190 Solved: 465[Submit][Status] ...
- 解决mysql 1040错误Too many connections的方法
从官方文档知道linux上面编译安装的mysql默认的连接为100个,这样对于网站的需求来说是远远不够的. mysql官方告诉我们需要修改max_connections的值,那么我们怎么去修改呢?有两 ...
- PAT-乙级-1040. 有几个PAT(25)
1040. 有几个PAT(25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 字符串APPAPT中包含了两个单 ...
- bzoj 1040 [ZJOI2008]骑士(基环外向树,树形DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1040 [题意] 给一个基环森林,每个点有一个权值,求一个点集使得点集中的点无边相连且权 ...
随机推荐
- BZOJ 2502: 清理雪道 [最小流]
2502: 清理雪道 题意:任意点出发任意次每条边至少经过一次最小花费. 下界1,裸最小流.... #include <iostream> #include <cstdio> ...
- 【模板小程序】求第n个质数
#include <iostream> #include <vector> using namespace std; int nth_prime(int n) { vector ...
- 撸一撸Spring Cloud Ribbon的原理
说起负载均衡一般都会想到服务端的负载均衡,常用产品包括LBS硬件或云服务.Nginx等,都是耳熟能详的产品. 而Spring Cloud提供了让服务调用端具备负载均衡能力的Ribbon,通过和Eure ...
- 读书共享 Primer Plus C-part11
第十四章结构和其他数据形式 关于fread以及fwrite fread(char* buff,int size,int count,FILE* fp) fwrite(char* buff,int si ...
- 初识vps,域名与购买,初步配置
终于还是到了这一天,不管我们是不是程序员,当我们想拥有自己的一个的博客,当我们想有自己的一个空间,当我们想在网上有一个自己可以随心所欲编写任何不被限制的仅仅是酷炫的效果,当我们想收录自己的技术,经历, ...
- NoSQLBooster for MongoDB的基本使用
连接 File -> Quik Connect ( Ctrl + Shift + N ) 或 Connect -> From URI 填入 mongodb://username:passw ...
- 使用 Homebrew 安装 Git
3.2.3 使用 Homebrew 安装 Git 2011-07-27 08:52 蒋鑫 机械工业出版社 字号:T | T 综合评级: 想读(13) 在读(6) 已读(8) 品书斋鉴(1) ...
- python进阶学习笔记(一)
python进阶部分要学习的内容: 学习目标: 1.函数式编程 1.1,什么是函数式编程 函数式编程是一种抽象计算的编程模式 不同语言的抽象层次不同: 函数式编程的特点: python支持的函数式编程 ...
- C/C++语言简介之发展历史
C语言之所以命名为C,是因为 C语言源自Ken Thompson发明的B语言,而 B语言则源自BCPL语言. 1967年,剑桥大学的Martin Richards对CPL语言进行了简化,于是产生了BC ...
- windows转mac-开发环境搭建(二):mac上java环境搭建
1.首先下载jdk,地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.安 ...