password 123

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97960#problem/A

题意:给国王生日可能区间【a,b】,死亡日期可能区间【c,d】,a《=b < c《=d,问国王可能最短寿命和最长寿命。

解法:min=c-b max=d-a

 //#define debug
//#define txtout
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double eps=1e-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=1e5+;
int main(){
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int a,b,c,d;
while(~scanf("%d%d%d%d",&a,&b,&c,&d),a|b|c|d){
printf("%d %d\n",c-b,d-a);
}
return ;
}

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97960#problem/B

题意:给16种颜色的rgb值,输入一个rgb,输出最接近的颜色,距离是欧几里得距离,多个距离相等输出靠前的。

解法:暴力测试。

 //#define debug
//#define txtout
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double eps=1e-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=1e5+;
char str[][]={"White","Silver","Gray","Black","Red","Maroon","Yellow","Olive","Lime","Green","Aqua","Teal","Blue","Navy","Fuchsia","Purple"};
int R[]={,,,,,,,,,,,,,,,};
int G[]={,,,,,,,,,,,,,,,};
int B[]={,,,,,,,,,,,,,,,};
int r,g,b;
int Square(int x){
return x*x;
}
int Distance2(int R,int G,int B){
return Square(R-r)+Square(G-g)+Square(B-b);
}
int solve(){
int id=;
int d=Distance2(R[],G[],B[]);
for(int i=;i<;i++){
int td=Distance2(R[i],G[i],B[i]);
if(d>td){
d=td;
id=i;
}
}
return id;
}
int main(){
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
while(~scanf("%d%d%d",&r,&g,&b),~r){
puts(str[solve()]);
}
return ;
}

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97960#problem/C

题意:输入T个队伍,P个问题,S次提交,问哪段时间内同时满足4个条件,1每个队都过题,2没有队全过ak,3每个题都有人过,4没有题被所有人过。保证这种时间段只有一个。

解法:按照提交时间排序,然后暴力测试。

 //#define debug
//#define txtout
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double eps=1e-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=5e3+;
int T,P,S,start_id,end_id;
struct Submission{
int teamID,hour,minute,second,total;
char problemID[];
bool result;
friend bool operator <(const Submission &a,const Submission &b){
return a.total<b.total;
}
void init(){
total=hour*+minute*+second;
}
}submission[M];
bool accepted[][];
void get_result(int id){
char c;
submission[id].result=false;
while(true){
c=getchar();
if(c=='\n') return ;
if(c=='Y') submission[id].result=true;
}
}
void init(){
start_id=-;
end_id=-;
for(int i=;i<S;i++){
submission[i].init();
}
for(int i=;i<=T;i++){
for(int j=;j<P;j++){
accepted[i][j]=false;
}
}
}
bool solved_at_least_one(int teamID){
for(int i=;i<P;i++){
if(accepted[teamID][i]) return true;
}
return false;
}
bool solved_all(int teamID){
for(int i=;i<P;i++){
if(!accepted[teamID][i]) return false;
}
return true;
}
bool at_least_one_team(int problemID){
for(int i=;i<=T;i++){
if(accepted[i][problemID]) return true;
}
return false;
}
bool solved_by_all(int problemID){
for(int i=;i<=T;i++){
if(!accepted[i][problemID]) return false;
}
return true;
}
bool judge(){
for(int i=;i<=T;i++){
if(solved_at_least_one(i)) continue;
return false;
}
for(int i=;i<=T;i++){
if(solved_all(i)) return false;
}
for(int i=;i<P;i++){
if(at_least_one_team(i)) continue;
return false;
}
for(int i=;i<P;i++){
if(solved_by_all(i)) return false;
}
return true;
}
void solve(){
init();
sort(submission,submission+S);
for(int i=;i<S;i++){
if(submission[i].result){
accepted[submission[i].teamID][submission[i].problemID[]-'A']=true;
}
if(judge()){
if(start_id==-) start_id=i;
end_id=i;
}
else{
if(start_id!=-) return ;
}
}
}
void out(int id){
if(id<||id>S-){
printf("--:--:--");
return ;
}
printf("%02d:%02d:%02d",submission[id].hour,submission[id].minute,submission[id].second);
}
int main(){
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
while(~scanf("%d%d%d",&T,&P,&S),T|P|S){
for(int i=;i<S;i++){
scanf("%d%s%d:%d:%d",&submission[i].teamID,submission[i].problemID,&submission[i].hour,&submission[i].minute,&submission[i].second);
get_result(i);
}
solve();
out(start_id);
putchar(' ');
if(end_id!=-) end_id++;
out(end_id);
putchar('\n');
}
return ;
}

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97960#problem/D

题意:输入n个电梯,输入每个电梯停m楼,输入m个楼的层号,从i楼到j楼花费时间是两者的距离。求从起点到终点最短时间。

解法:同一个电梯的任意两层楼建双向边,距离为绝对值,单元最短路。

spfa

 //#define debug
//#define txtout
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double eps=1e-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=2e2+;
int W[M][M];
int n,s,t;
struct Elevator {
int m;
int floor[M];
} elevator[];
class Spfa { ///最短路快速算法O(E*k)(k~=2)
typedef int typec;///边权的类型
static const int ME=4e4+;///边的个数
static const int MV=2e2+;///点的个数
struct E {
int v,next;
typec w;
} e[ME];
int n,le,head[MV],inque[MV],pre[MV],i,u,v;
typec dist[MV];
bool used[MV];
queue<int> q;
public:
void init(int tn) { ///传入点的个数
n=tn;
le=;
for(i=; i<=n; i++) head[i]=-;
}
void add(int u,int v,typec w) {
e[le].v=v;
e[le].w=w;
e[le].next=head[u];
head[u]=le++;
}
bool solve(int s) { ///传入起点,存在负环返回false
for(i=; i<=n; i++) {
dist[i]=inf;
used[i]=true;
inque[i]=;
pre[i]=-;
}
used[s]=false;
dist[s]=;
inque[s]++;
while(!q.empty()) q.pop();
q.push(s);
while(!q.empty()) {
u=q.front();
q.pop();
used[u]=true;
for(i=head[u]; ~i; i=e[i].next) {
v=e[i].v;
if(dist[v]>dist[u]+e[i].w) {
dist[v]=dist[u]+e[i].w;
pre[v]=u;
if(!used[v]) continue;
used[v]=false;
q.push(v);
inque[v]++;
if(inque[v]>n) return false;
}
}
}
return true;
}
typec getdist(int id) {
return dist[id];
}
int getpre(int id) {
return pre[id];
}
} spfa;
void add(int u,int v,int w) {
if(W[u][v]>w) {
W[u][v]=w;
W[v][u]=w;
}
}
void init() {
mt(W,0x3f);
for(int i=; i<n; i++) {
int m=elevator[i].m;
for(int j=; j<m; j++) {
for(int k=j+; k<m; k++) {
int u=elevator[i].floor[j];
int v=elevator[i].floor[k];
int w=abs(u-v);
add(u,v,w);
}
}
}
}
int solve() {
init();
spfa.init();
for(int i=;i<;i++){
for(int j=;j<;j++){
if(W[i][j]==inf) continue;
spfa.add(i,j,W[i][j]);
}
}
spfa.solve(s);
return spfa.getdist(t);
}
int main() {
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
while(~scanf("%d%d%d",&n,&s,&t),n|s|t) {
for(int i=; i<n; i++) {
scanf("%d",&elevator[i].m);
for(int j=; j<elevator[i].m; j++) {
scanf("%d",&elevator[i].floor[j]);
}
}
printf("%d\n",solve());
}
return ;
}

priority——queue dij

 //#define debug
//#define txtout
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double eps=1e-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=2e2+;
int W[M][M];
int n,s,t;
struct Elevator {
int m;
int floor[M];
} elevator[];
class Dijkstra { ///Dijkstra 堆优化O(E*log(V))
typedef int typec;///边权的类型
static const int ME=4e4+;///边的个数
static const int MV=2e2+;///点的个数
struct Q {
int id;
typec w;
friend bool operator <(const Q &a,const Q &b) {
return a.w>b.w;
}
} now;
priority_queue<Q> q;
struct E {
int v,next;
typec w;
} e[ME];
int n,le,head[MV],pre[MV],u,v,i;
typec dist[MV],w;
bool used[MV];
public:
void init(int tn) {///传入点的个数
n=tn;
le=;
for(i=; i<=n; i++) head[i]=-;
}
void add(int u,int v,typec w) {
e[le].v=v;
e[le].w=w;
e[le].next=head[u];
head[u]=le++;
}
void solve(int s) {///传入起点
for(i=; i<=n; i++) {
used[i]=true;
dist[i]=inf;
pre[i]=-;
}
dist[s]=;
now.id=s;
now.w=;
while(!q.empty()) q.pop();
q.push(now);
while(!q.empty()) {
now=q.top();
q.pop();
u=now.id;
if(!used[u]) continue;
used[u]=false;
for(i=head[u]; ~i; i=e[i].next) {
v=e[i].v;
w=e[i].w;
if(used[v]&&dist[v]>w+dist[u]) {
dist[v]=w+dist[u];
pre[v]=u;
now.id=v;
now.w=dist[v];
q.push(now);
}
}
}
}
typec getdist(int id) {
return dist[id];
}
int getpre(int id) {
return pre[id];
}
} spfa;
void add(int u,int v,int w) {
if(W[u][v]>w) {
W[u][v]=w;
W[v][u]=w;
}
}
void init() {
mt(W,0x3f);
for(int i=; i<n; i++) {
int m=elevator[i].m;
for(int j=; j<m; j++) {
for(int k=j+; k<m; k++) {
int u=elevator[i].floor[j];
int v=elevator[i].floor[k];
int w=abs(u-v);
add(u,v,w);
}
}
}
}
int solve() {
init();
spfa.init();
for(int i=; i<; i++) {
for(int j=; j<; j++) {
if(W[i][j]==inf) continue;
spfa.add(i,j,W[i][j]);
}
}
spfa.solve(s);
return spfa.getdist(t);
}
int main() {
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
while(~scanf("%d%d%d",&n,&s,&t),n|s|t) {
for(int i=; i<n; i++) {
scanf("%d",&elevator[i].m);
for(int j=; j<elevator[i].m; j++) {
scanf("%d",&elevator[i].floor[j]);
}
}
printf("%d\n",solve());
}
return ;
}

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97960#problem/F

题意:输入一些时间,有正有负,最后输出他们的和。

解法:把字符串的整数处理出来累加。

 //#define debug
//#define txtout
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double eps=1e-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=1e2+;
char a[M];
int solve(){
int sign=;
if(a[]=='-') sign=-;
int i;
int hour=;
for(i=;a[i];i++){
if(!isdigit(a[i])) break;
hour*=;
hour+=a[i]-'';
}
int minute=;
i++;
for(;a[i];i++){
minute*=;
minute+=a[i]-'';
}
return (hour*+minute)*sign;
}
int main(){
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int sum=;
while(~scanf("%s",a)){
if(a[]=='$'||a[]=='#'){
printf("%d:%02d\n",sum/,sum%);
sum=;
continue;
}
sum+=solve();
}
return ;
}

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=97960#problem/G

题意:n个城市,m条无向边,k条龙,给出图,和龙所在城市c,初始脑袋的个数s,每分钟增加的脑袋数n。每个勇士每分钟可以砍一个龙头或者走到一个相邻的城市。可以决定勇士一开始的位置。问最少几个勇士可以杀死所有的龙。

解法:如果龙的每分钟增加n小于勇士的总数,那总有一天能杀完这些龙,如果n》=勇士的总数,那必须在第一天将s全砍了。最后答案是每个连通块需要的勇士相加,对每个连通块可以二分勇士数量,验证时判断n》=总数的龙的s求和是否小于等于mid。

 //#define debug
//#define txtout
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define mt(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const double eps=1e-;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const int M=1e3+;
struct E{
int u,v;
}e[M*M];
struct Dragon{
int c,s,n;
}dragon[M];
vector<int> g[M],dragon_id;
bool vis[M];
int n,m,k;
void add(int u,int v){
g[u].push_back(v);
g[v].push_back(u);
}
void init(){
for(int i=;i<=n;i++){
g[i].clear();
vis[i]=false;
}
for(int i=;i<m;i++){
add(e[i].u,e[i].v);
}
}
bool judge(int mid){
int len=dragon_id.size();
int sum=;
for(int i=;i<len;i++){
if(dragon[dragon_id[i]].n<mid) continue;
sum+=dragon[dragon_id[i]].s;
}
return sum<=mid;
}
int get_cost(){
int len=dragon_id.size();
int L=,R=;
for(int i=;i<len;i++){
R=max(R,dragon[dragon_id[i]].n+);
}
int result=R;
while(L<=R){
int mid=(L+R)>>;
if(judge(mid)){
result=mid;
R=mid-;
}
else{
L=mid+;
}
}
return result;
}
void dfs(int u){
vis[u]=true;
for(int i=;i<k;i++){
if(dragon[i].c==u) dragon_id.push_back(i);
}
int len=g[u].size();
for(int i=;i<len;i++){
int v=g[u][i];
if(vis[v]) continue;
dfs(v);
}
}
int solve(){
init();
int result=;
for(int i=;i<=n;i++){
if(vis[i]) continue;
dragon_id.clear();
dfs(i);
result+=get_cost();
}
return result;
}
int main(){
#ifdef txtout
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
while(~scanf("%d%d%d",&n,&m,&k),n|m|k){
for(int i=;i<m;i++){
scanf("%d%d",&e[i].u,&e[i].v);
}
for(int i=;i<k;i++){
scanf("%d%d%d",&dragon[i].c,&dragon[i].s,&dragon[i].n);
}
printf("%d\n",solve());
}
return ;
}

end

matrix_last_acm_5的更多相关文章

随机推荐

  1. delphi的几个特别关键字 object absolute

    1.object关键字相当于C++中的struct, record定义个结构体只能定义数据,而object可以定义方法,默认都是public的.   代码示例如下: TTest = record na ...

  2. 银河英雄传说 (codevs 1540) 题解

    [问题描述] 公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争.泰 ...

  3. 第十三章 调试及安全性(In .net4.5) 之 验证程序输入

    1. 概述 本章介绍验证程序输入的重要性以及各种验证方法:Parse.TryParse.Convert.正则表达式.JavaScriptSerializer.XML Schemas. 2. 主要内容 ...

  4. python 遍历文件夹

    import os import os.path rootdir = “d:\data” # 指明被遍历的文件夹 for parent,dirnames,filenames in os.walk(ro ...

  5. Python脚本控制的WebDriver 常用操作 <六> 打印当前页面的title及url

    下面将使用WebDriver来答应浏览器页面的title和访问的地址信息 测试用例场景 测试中,访问1个页面然后判断其title是否符合预期是很常见的1个用例: 假设1个页面的title应该是'hel ...

  6. python正则式

    (|):匹配多个正则表达式模式.at|home 匹配at和home (.):匹配任意一个单个字符.f.o匹配f和o中间任意的字符,如foo,f#o (^ / $ / \b / \B):^从字符串开头开 ...

  7. Ruby判断文件是否存在

    flag = FileTest::exist?("LochNessMonster") flag = FileTest::exists?("UFO") # exi ...

  8. Orcle 系统表

    oracle系统表大全 一.管理员 1.用户: select username from dba_users; 改口令 alter user spgroup identified by spgtest ...

  9. Redhat 6环境下安装Oracle 12c的方法

    Step 1: 要在Linux上安装Oracle,需要在安装Oracle之前安装好相应的软件包,在不同操作系统环境下,对软件包的要求各不相同.具体对应的软件包,见官网文档:https://docs.o ...

  10. eclipse java 空心J文件的回复

    eclipse中的空心J的java文件,表示当前文件不包含在项目中进行编译,而仅仅是当做资源存在项目中. 解决方案如下: 1.鼠标右击当前空心j文件,-->build path-->inc ...