pat1071-1080
1071
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e3+5;
typedef long long ll;
#define MP(x, y) make_pair(x, y);
char a[1048580];
map<string, int> mp;
map<string, int> ::iterator it;
int main() {
gets(a);
int len = strlen(a);
string tt;
for(int i = 0; i <= len; ++i) {
if( (a[i] >= 'a' && a[i] <= 'z') || (a[i] >= 'A' && a[i] <= 'Z') || (a[i] >= '0' && a[i] <= '9') ) {
if(a[i] >= 'A' && a[i] <= 'Z') a[i] = a[i]-'A'+'a';
tt += a[i];
}
else {
if(tt.size() > 0) mp[tt] ++;
tt.clear();
}
}
string a1; int a2 = -1;
for(it = mp.begin(); it != mp.end(); ++it) {
if(a2 < it->second) {
a1 = it->first;
a2 = it->second;
}
}
printf("%s %d\n", a1.c_str(), a2);
return 0;
}
1072 一道非常麻烦的最短路问题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e3+50;
typedef long long ll;
#define MP(x, y) make_pair(x, y);
int n,m,k,d;
map<string, int> mp;
double ans1, ans2; string ans3;
char nam[N][10];
int tol;
struct Node{
int to, nx, di;
}E[N*N*2];
int head[N], tot;
void add(int fr, int to, int di) {
E[tot].to = to; E[tot].di = di; E[tot].nx = head[fr]; head[fr] = tot ++;
}
struct Hode{
int po, di;
Hode(int a=0, int b=0):po(a), di(b) {}
bool operator< (const Hode & T) const {
return di > T.di;
}
};
int dis[N];
int vis[N];
string change(int x, int ty) {
vector<int> vc;
while(x) {
vc.push_back(x % 10);
x /= 10;
}
string tmp;
if(ty) tmp += 'G';
for(int i = vc.size()-1; i >= 0; --i) {
tmp += vc[i]+'0';
}
return tmp;
}
void dij(int x) {
memset(vis, 0, sizeof(vis));
memset(dis, INF, sizeof(dis));
dis[x] = 0;
priority_queue<Hode> Q;
Q.push(Hode(x, dis[x]));
while(!Q.empty()) {
int po = Q.top().po; Q.pop();
if(vis[po]) continue;
vis[po] = 1;
for(int i = head[po]; ~i; i = E[i].nx) {
int to = E[i].to;
if(dis[to] > dis[po] + E[i].di) {
dis[to] = dis[po] + E[i].di;
Q.push(Hode(to, dis[to]));
}
}
}
int fl = 1; int tmp = INF; int all = 0;
for(int i = 1; i <= n; ++i) {
string tt = change(i, 0);
int id = mp[tt];
if( dis[id] > d) {
fl = 0; break;
}
if(dis[id] < tmp) {
tmp = dis[id];
}
all += dis[id];
// printf("%d ", dis[id]);
}
// printf("%d %.2f %s\n", fl, all*1.0/n, nam[x]);
if(fl && tmp*1.0 > ans1) {
ans3 = nam[x];
ans1 = tmp*1.0;
ans2 = all*1.0 / n;
}else if(fl && tmp*1.0 == ans1 && all*1.0/n < ans2) {
ans2 = all*1.0 / n;
ans3 = nam[x];
}
}
int main() {
while(~scanf("%d %d %d %d",&n, &m, &k, &d)) {
ans1 = -1.0;
mp.clear(); tot = 0;
memset(head, -1, sizeof(head));
tol = 0;
for(int i = 0; i < k; ++i) {
char s1[10]; char s2[10]; int a;
scanf("%s %s %d", s1, s2, &a);
if(mp.find(s1) == mp.end()) {
++tol;
for(int j = 0; j <= strlen(s1); ++j) nam[tol][j] = s1[j];
mp[s1] = tol;
}
if(mp.find(s2) == mp.end()) {
++tol;
for(int j = 0; j <= strlen(s2); ++j) nam[tol][j] = s2[j];
mp[s2] = tol;
}
int t1 = mp[s1]; int t2 = mp[s2];
// if(s1[0] == 'G' && s2[0] == 'G') continue;
add(t1, t2, a); add(t2, t1, a);
}
for(int i = 1; i <= m; ++i) {
string tt = change(i, 1);
// printf("%s %d\n", tt.c_str(), mp[tt]);
int id = mp[tt];
dij(id);
}
if(ans1 == -1) printf("No Solution\n");
else {
printf("%s\n%.1f %.1f\n", ans3.c_str(), round(ans1*10) /10, round(ans2*10)/10 );
}
}
return 0;
}
1073
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e3+50;
typedef long long ll;
#define MP(x, y) make_pair(x, y);
char s[10000];
char t[10000];
int main() {
while(~scanf("%s", s)) {
int len = strlen(s);
int cnt = 0;
if(s[0] == '-') printf("-");
int edpoi = -1;
int tag = 0;
for(int i = 1; i < len; ++i) {
if(s[i] == '.') edpoi = cnt-1;
else if(s[i] == 'E') {
tag = i; break;
}else t[cnt++] = s[i];
}
if(edpoi == -1) edpoi = cnt-1;
int tmp = 0;
for(int i = tag+2; i < len; ++i) {
tmp = tmp*10 + s[i]-'0';
}
if(s[tag+1] == '-') tmp *= -1;
// printf("%d %d\n", edpoi, tmp);
int nwpoi = edpoi + tmp;
if(nwpoi < 0) {
printf("0.");
for(int i = 0; i < abs(nwpoi+1); ++i) printf("0");
}
for(int i = 0; i < cnt; ++i) {
printf("%c", t[i]);
if(i == nwpoi && i != cnt-1) printf(".");
}
if(nwpoi > cnt-1) {
for(int i = 0; i < nwpoi-cnt+1; ++i) printf("0");
}
printf("\n");
}
return 0;
}
1074
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e6+5;
typedef long long ll;
#define MP(x, y) make_pair(x, y);
int key[N]; int nx[N];
vector<int> tmp;
vector<int> ans;
int head, n, k;
void dfs(int x) {
if(x == -1) return;
tmp.push_back(x);
if(tmp.size() == k) {
for(int i = k-1; i >= 0; --i) {
ans.push_back(tmp[i]);
}
tmp.clear();
}
dfs(nx[x]);
}
int main() {
while(~scanf("%d %d %d", &head, &n, &k)) {
for(int i = 0; i < n; ++i) {
int a, b, c; scanf("%d %d %d", &a, &b, &c);
key[a] = b; nx[a] = c;
}
dfs(head);
for(int i = 0; i < tmp.size(); ++i) ans.push_back(tmp[i]);
for(int i = 0; i < ans.size(); ++i) {
printf("%05d %d ", ans[i], key[ans[i]]);
if(i == ans.size()-1) printf("-1\n");
else printf("%05d\n", ans[i+1]);
}
}
return 0;
}
1075
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e4+5;
typedef long long ll;
#define MP(x, y) make_pair(x, y);
int n,m,k;
int mark[6];
map<int, int> mp;
struct Node{
int num;
int grade[6];
}E[N];
int tot;
int cmp(Node a, Node b) {
int a1 = 0; int b1 = 0;
int a2 = 0; int b2 = 0;
for(int j = 1; j <= k; ++j) {
a1 += a.grade[j], b1 += b.grade[j];
if(a.grade[j] == -1) a1 ++; else if(a.grade[j] == -2) a1 += 2;
if(b.grade[j] == -1) b1 ++; else if(b.grade[j] == -2) b1 += 2;
if(a.grade[j] == mark[j]) a2 ++;
if(b.grade[j] == mark[j]) b2 ++;
}
if(a1 != b1) return a1 > b1;
else if(a2 != b2) return a2 > b2;
else return a.num < b.num;
}
int main() {
while(~scanf("%d %d %d", &n, &k, &m)) {
tot = 0;
mp.clear();
for(int i = 1; i <= k; ++i) scanf("%d", &mark[i]);
for(int i = 0; i < m; ++i) {
int a, b, c; scanf("%d %d %d", &a, &b, &c);
if(mp.find(a) == mp.end()) {
mp[a] = ++tot;
for(int j = 1; j <= k; ++j) E[tot].grade[j] = -2;
}
int id = mp[a];
E[id].num = a;
E[id].grade[b] = max(E[id].grade[b], c);
}
sort(E+1, E+tot+1, cmp);
int pre = -1, prerank;
int cnt = 0;
for(int i = 1; i <= tot; ++i) {
int no = 0; int all = 0; int nwrank;
for(int j = 1; j <= k; ++j) {
if(E[i].grade[j] <= -1) no ++;
all += E[i].grade[j];
if(E[i].grade[j] == -1) all ++;
else if(E[i].grade[j] == -2) all += 2;
}
if(no == k) { cnt ++; continue; }
if(pre == all) nwrank = prerank;
else nwrank = i-cnt;
printf("%d %05d %d", nwrank, E[i].num, all);
for(int j = 1; j <= k; ++j) {
if(E[i].grade[j] == -2) printf(" -");
else if(E[i].grade[j] == -1) printf(" 0");
else printf(" %d", E[i].grade[j]);
}
printf("\n");
pre = all; prerank = nwrank;
}
}
return 0;
}
1076
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e3+5;
typedef long long ll;
#define MP(x, y) make_pair(x, y)
int n,l;
struct Node{
int to, nx;
}E[N*N*2];
int head[N], tot;
void add(int fr, int to) {
E[tot].to = to; E[tot].nx = head[fr]; head[fr] = tot++;
}
int vis[N];
void bfs(int x) {
for(int i = 1; i <= n; ++i) vis[i] = 0;
vis[x] = 1;
queue<pair<int, int> > Q;
Q.push(MP(x, 0));
int ans = 0;
while(!Q.empty()) {
int po = Q.front().first; int dep = Q.front().second; Q.pop();
if(dep > l) break;
ans ++;
for(int i = head[po]; ~i; i = E[i].nx) {
int to = E[i].to;
if(!vis[to]) {
vis[to] = 1;
Q.push(MP(to, dep+1));
}
}
}
printf("%d\n",ans-1);
}
int main() {
while(~scanf("%d %d", &n, &l)) {
memset(head, -1, sizeof(head));
tot = 0;
for(int i = 1; i <= n; ++i) {
int a; scanf("%d", &a);
for(int j = 0; j < a; ++j) {
int b; scanf("%d", &b);
add(b, i);
}
}
int k; scanf("%d", &k);
for(int i = 1; i <= k; ++i) {
int a; scanf("%d", &a);
bfs(a);
}
}
return 0;
}
1077
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e3+5;
typedef long long ll;
#define MP(x, y) make_pair(x, y)
char s[105][300];
int main() {
int n;
while(~scanf("%d", &n)) {
getchar();
for(int i = 0; i < n; ++i) {
gets(s[i]);
// printf("tt %s\n", s[i]);
for(int j = 0; j < strlen(s[i])/2; ++j) {
swap(s[i][j], s[i][strlen(s[i])-j-1]);
}
// printf("%s\n", s[i]);
}
vector<char> ans;
int fl = 0;
while(1) {
int nw = 1;
for(int i = 1; i < n; ++i) {
if(s[i][fl] != s[i-1][fl] || s[i][fl] == 0) {
nw = 0; break;
}
}
if(!nw) break;
else ans.push_back(s[0][fl]);
fl ++;
}
if(ans.size() == 0) printf("nai\n");
else {
for(int i = ans.size()-1; i >= 0; --i) printf("%c", ans[i]); printf("\n");
}
}
return 0;
}
1078 这道题提醒了我得把 数据结构学好,等题目刷完我要开始看数据结构啦
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e4+5;
typedef long long ll;
#define MP(x, y) make_pair(x, y)
int has[N];
int prime(int x) {
if(x == 1) return 0;
if(x == 2) return 1;
for(int i = 2; i <= sqrt(x); ++i) {
if(x % i == 0) return 0;
}
return 1;
}
int main() {
int msize, n;
while(~scanf("%d %d", &msize, &n)) {
memset(has, 0, sizeof(has));
while(1) {
if(prime(msize)) break;
msize ++;
}
for(int i = 0; i < n; ++i) {
int a; scanf("%d", &a);
if(i) printf(" ");
if(!has[a%msize]) {
has[a%msize] = a;
printf("%d", a%msize);
}else{
int fl = 0;
for(int j = 1; j < msize; ++j) {
int tmp = (a + j*j) % msize;
// if(tmp >= msize) break;
if(!has[tmp]) {
has[tmp] = a;
fl = 1;
printf("%d", tmp);
break;
}
}
if(!fl) printf("-");
}
}
printf("\n");
}
return 0;
}
1079
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<map>
#include<set>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+5;
typedef long long ll;
#define MP(x, y) make_pair(x, y)
int n; double p, r;
struct Node{
int to, nx;
}E[N*1000];
int head[N]; int tot;
void add(int fr, int to) {
E[tot].to = to; E[tot].nx = head[fr]; head[fr] = tot++;
}
int product[N]; int has[N];
double ans;
void dfs(int x, double price) {
if(has[x]) {
ans += product[x] * price;
return;
}
for(int i = head[x]; ~i; i = E[i].nx) {
int to = E[i].to;
dfs(to, price*(1+ r/100));
}
}
int main() {
while(~scanf("%d %lf %lf", &n, &p, &r)) {
memset(head, -1, sizeof(head));
memset(has, 0, sizeof(has));
tot = 0; ans = 0;
for(int i = 0; i < n; ++i) {
int a; scanf("%d", &a);
for(int j = 0; j < a; ++j) {
int b; scanf("%d", &b);
add(i, b);
}
if(!a) {
scanf("%d", &a);
product[i] = a; has[i] = 1;
}
}
dfs(0, p);
printf("%.1f\n", ans);
}
return 0;
}
1080
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 4e4+5;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
const int MOD = 1e9+7;
int quota[105];
int Ge[N], Gi[N], Ch[N][6];
int Id[N];
int cmp(int a, int b) {
if(Ge[a]+Gi[a] != Ge[b]+Gi[b]) return Ge[a]+Gi[a] > Ge[b]+Gi[b];
else return Ge[a] > Ge[b];
}
vector<int> ans[105];
int has[N];
int n,m,k;
void solve(int fr, int to) {
int temp[105];
for(int i = 0; i < k; ++i) {
int cnt = 0;
for(int j = 0; j < m; ++j) temp[j] = ans[j].size();
for(int j = fr; j <= to; ++j) {
int tt = Ch[Id[j]][i];
if(has[Id[j]]) continue;
cnt ++;
if(temp[tt] < quota[tt]) {
ans[tt].push_back(Id[j]);
has[Id[j]] = 1;
}
}
if(!cnt) break;
}
}
int main() {
while(~scanf("%d %d %d", &n, &m, &k)) {
memset(has, 0, sizeof(has));
for(int i = 0; i < m; ++i) ans[i].clear();
for(int i = 0; i < m; ++i) scanf("%d", "a[i]);
for(int i = 0; i < n; ++i) {
scanf("%d %d", &Ge[i], &Gi[i]);
for(int j = 0; j < k; ++j) {
scanf("%d", &Ch[i][j]);
}
}
for(int i = 0; i <= n; ++i) Id[i] = i;
sort(Id, Id+n, cmp);
Ge[n] = INF;
int fr = 0; int to = -1;
for(int i = 0; i < n; ++i) {
to ++;
if(Ge[Id[i]]+Gi[Id[i]] != Ge[Id[i+1]]+Gi[Id[i+1]] || Ge[Id[i]] != Ge[Id[i+1]]) solve(fr, to), fr = to+1;
}
for(int i = 0; i < m; ++i) {
sort(ans[i].begin(), ans[i].end());
for(int j = 0; j < ans[i].size(); ++j) {
if(j) printf(" "); printf("%d",ans[i][j]);
}
printf("\n");
}
}
return 0;
}
pat1071-1080的更多相关文章
- codevs 1080 线段树点修改
先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...
- hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新
#1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...
- NYOJ题目1080年龄排序
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtMAAAJVCAIAAACTf+6jAAAgAElEQVR4nO3dO1Lj3NbG8W8Szj0QYg ...
- codevs 1080 线段树练习
链接:http://codevs.cn/problem/1080/ 先用树状数组水一发,再用线段树水一发 树状数组代码:84ms #include<cstdio> #include< ...
- (转)深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0
深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0 发表于2016年07月15号由52nlp 接上文<深度学习主机攒机小记>,这台GTX10 ...
- HDU 1080
http://acm.hdu.edu.cn/showproblem.php?pid=1080 二维最长公共子序列 #include <iostream> #include <cstd ...
- poj 1080 Human Gene Functions(dp)
题目:http://poj.org/problem?id=1080 题意:比较两个基因序列,测定它们的相似度,将两个基因排成直线,如果需要的话插入空格,使基因的长度相等,然后根据那个表格计算出相似度. ...
- POJ 1080 Human Gene Functions -- 动态规划(最长公共子序列)
题目地址:http://poj.org/problem?id=1080 Description It is well known that a human gene can be considered ...
- poj 1080 dp如同LCS问题
题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...
- dp poj 1080 Human Gene Functions
题目链接: http://poj.org/problem?id=1080 题目大意: 给两个由A.C.T.G四个字符组成的字符串,可以在两串中加入-,使得两串长度相等. 每两个字符匹配时都有个值,求怎 ...
随机推荐
- BZOJ 4455: [Zjoi2016]小星星 [容斥原理 树形DP]
4455: [Zjoi2016]小星星 题意:一个图删掉一些边形成一棵树,告诉你图和树的样子,求让图上的点和树上的点对应起来有多少方案 看了很多题解又想了一段时间,感觉题解都没有很深入,现在大致有了自 ...
- BZOJ 3620: 似乎在梦中见过的样子 [KMP 暴力]
和我签订契约,成为魔法少女吧 题意:求所有形似于A+B+A 的子串的数量 , 且len(A)>=k,len(B)>=1 位置不同其他性质相同的子串算不同子串,位置相同但拆分不同的子串算同一 ...
- C语言实现数据结构中的堆创建,堆排序
#include "stdio.h"#include "stdlib.h"void swap(int *a,int *b)//交换两个数{int t;t=*a; ...
- .NET图表控件(LightningChart )的用法
概述 LightningChart (LightningChart Ultimate) 软件开发工具包是微软Visual Studio 的一个插件,专攻大数据可视化呈现问题,用于 WPF(Window ...
- [Python Study Notes]cpu信息
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- java泛型类的继承规则
首先看一看java泛型类的使用: /** * 一个泛型方法:使程序更加安全 * 并且能被更多的使用 * @author 丁** * * @param <T> */ class Pair&l ...
- shell编程之SHELL基础(1)
shell脚本基础 shell是一个命令行解释器,她为互用提供了一个想linux内核发送请求以便运行程序的界面系统级程序,用户可以用shell来启动.挂起.停止甚至编写一些程序. shell还是一个功 ...
- JAVA受检异常和非受检异常举例
受检异常和非受检异常(运行时异常)举例 RuntimeException(即非受检异常): RuntimeException在默认情况下会得到自动处理,所以通常用不着捕获RuntimeExceptio ...
- 将Object对象转换成Map 属性名和值的形式
将Java对象转换成Map的键值对形式 代码: package cn.lonelcoud.util; import com.sun.deploy.util.StringUtils; import ja ...
- 使用maven搭建hibernate的pom文件配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...