T1:P1518-两只塔姆沃斯牛 The Tamworth Two


题目大意

两个东西,按照一个方向前进,他们撞到墙壁会顺时针90°,求他们多久后相遇。


解题思路

暴力模拟


code

// luogu-judger-enable-o2
#include<cstdio>
#include<iostream>
using namespace std;
const int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
struct node{int x,y,f;
}f,c;
char a[11][11];
int main()
{for(int i=1;i<=10;i++)for(int j=1;j<=10;j++){cin>>a[i][j];if(a[i][j]=='F') f=(node){i,j,0};if(a[i][j]=='C') c=(node){i,j,0};}for(int i=1;i<=100000;i++){if(a[f.x+dx[f.f]][f.y+dy[f.f]]=='*'||f.x==10&&f.f==2||f.y==10&&f.f==1||f.x==1&&f.f==0||f.y==1&&f.f==3)f.f=(f.f+1)%4;else f.x+=dx[f.f],f.y+=dy[f.f];if(a[c.x+dx[c.f]][c.y+dy[c.f]]=='*'||c.x==10&&c.f==2||c.y==10&&c.f==1||c.x==1&&c.f==0||c.y==1&&c.f==3)c.f=(c.f+1)%4;else c.x+=dx[c.f],c.y+=dy[c.f];if(f.x==c.x&&f.y==c.y){printf("%d",i);return 0;}}printf("0");
}

T2:P1529-回家 Bessie Come Home


题目大意

26个小写字母和26个大写字母用边连接形成带权无向图
求离Z最近的大写字母。


解题思路

从Z出发,然后计算每个大写字母的距离最小的。


code

// luogu-judger-enable-o2
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
using namespace std;
struct line{int from,to,w,next;
}a[200010];
int tot,ls[100],f[100],p,s,w,ans;
char x,y;
bool v[100];
queue<int> q;
void addl(int x,int y,int w)
{a[++tot]=(line){x,y,w,ls[x]};ls[x]=tot;}
void spfa()
{q.push(s);v[s]=true;memset(f,127/3,sizeof(f));f[s]=0;while(!q.empty()){int x=q.front();q.pop();for(int i=ls[x];i;i=a[i].next){int y=a[i].to;if(f[x]+a[i].w<f[y]){f[y]=f[x]+a[i].w;if(!v[y]){v[y]=true;q.push(y);}}}v[x]=false;}
}
int main()
{scanf("%d",&p);for(int i=1;i<=p;i++){cin>>x>>y>>w;if(x<='Z') x-='A'-1;else x-='a'-27;if(y<='Z') y-='A'-1;else y-='a'-27;addl(x,y,w);addl(y,x,w);}s=26;spfa();f[ans]=2147483647;for(int i=1;i<=25;i++)if(f[i]<f[ans]) ans=i;printf("%c %d",ans+'A'-1,f[ans]);
}

T3-P1530 分数化小数 Fractions to Decimals


题目大意

将一个分数表示成小数形式。


解题思路

因为懒得写所以用了一道更难的题的方法。


code

// luogu-judger-enable-o2
#include<cstdio>
#include<algorithm>
using namespace std;
int t;
int a,b,k,d,ans1,s;
int gcd(int a,int b)
{if (a%b==0) return b;return gcd(b,a%b);
}
int ksm(int x,int k)
{int ans=0;while(k){if (k&1) ans=(ans+x)%b;x=(x*2)%b;k>>=1;}return ans;
}
int qsm(int x,int k)
{int ans=1;while(k){if (k&1) ans=ksm(ans,x);x=ksm(x,x);k>>=1;}return ans;
}
int phi(int x)
{int ans=x;for (int i=2;i*i<=x;i++)if (x%i==0) {ans=ans/i*(i-1);while (x%i==0) x/=i;}if (x>1) ans=ans/x*(x-1);return ans;
}
void print(int a,int b,int hlen,int rlen)
{s++;a=a%b*10;if(hlen+rlen==0)hlen=1;for(int i=1;i<=hlen;i++){printf("%d",a/b);s++;if(s==76) printf("\n"),s=0;a=a%b*10;}if(rlen){printf("(");s++;if(s==76) printf("\n"),s=0;for(int i=1;i<=rlen;i++){printf("%d",a/b);s++;if(s==76) printf("\n"),s=0;a=a%b*10;}printf(")");s++;if(s==76) printf("\n"),s=0;}
}
int main()
{//freopen("out.txt","w",stdout);scanf("%d%d",&a,&b);printf("%d.",a/b);int k=a/b;if(!k) s=1;while(k){s++;if(s==76) printf("\n"),s=0;k/=10;}int ba=a,bb=b;k=10;ans1=0;int d=gcd(a,b);a/=d;b/=d;d=gcd(b,k);while ((d=gcd(b,k))>1) b/=d,ans1++;if (b==1) {print(ba,bb,ans1,0);return 0;}int x,y;x=y=phi(b);for (int i=2;i*i<=x;i++)if (!(y%i)){while (!(x%i)&&qsm(k,x/i)==1) x/=i;do y/=i; while(!(y%i));}if (y>1&&qsm(k,x/y)==1) x/=y;print(ba,bb,ans1,x);
}

USACO2.4の其中3道水题【模拟,图论】相关推荐

  1. MOCTF-Web-一道水题

    首先我们看看题目: 进入传送门查看:http://119.23.73.3:5001/web1/ 水题嘛,直接查看源码搜索flag,得到flag

  2. 【HDU - 1870】愚人节的礼物(水题模拟 思想类似于栈?)

    题干: 四月一日快到了,Vayko想了个愚人的好办法--送礼物.嘿嘿,不要想的太好,这礼物可没那么简单,Vayko为了愚人,准备了一堆盒子,其中有一个盒子里面装了礼物.盒子里面可以再放零个或者多个盒子 ...

  3. 1503171912-ny-一道水题

    一道水题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 今天LZQ在玩一种小游戏,可是这游戏数有一点点的大,他一个人玩的累.想多拉一些人进来帮帮他.你能写一个程序帮 ...

  4. HDU1555 How many days?【水题+模拟】

    How many days? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  5. CDOJ 763 树上的鸟儿(水题/模拟题)

    树上的鸟儿 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) 作为电子科大的一员, ...

  6. 【HDU - 2398 】Savings Account (水题模拟)

    题干: Suppose you open a savings account with a certain initial balance. You will not make any withdra ...

  7. *【CodeForces - 574A】Bear and Elections (优先队列,水题模拟)

    题干: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections a ...

  8. 【HDU - 1702 】ACboy needs your help again! (栈和队列,水题模拟)

    题干: ACboy was kidnapped!!  he miss his mother very much and is very scare now.You can't image how da ...

  9. 2014年西安区域赛的几道水题(A. F. K)

    A . 问一组数能否全部被3整除 K. S1 = A, S2 = B, Si = |Si-1  -  Si-2|; 一直循环问, 出现了多少不同的数: 多模拟几组数, 可以发现和辗转相除法有很大关系 ...

最新文章

  1. 重定向、别名、绝对路径、相对路径 详解
  2. 云计算安全威胁集中营
  3. 组策略(八)使用使用自定义RealVNC adm模板对域内工作站设置统一标准设置
  4. Button的使用(十三):设置可见性
  5. Xlua文件在热更新中调用方法
  6. mysql必知必会_5天学完《MySQL必知必会》学习笔记之第四天
  7. 【ElasticSearch】Es 源码之 Discovery DiscoveryModule Coordinator 源码解读
  8. 【榜首团队专访】冲刺复赛,他们有绝招
  9. day055056Django之多表操作,多表查询
  10. 追本溯源:字符串及编码
  11. 使用w3m访问页面执行函数
  12. Total和Tellurian签署意向性协议,对Driftwood项目和2.5 mtpa LNG进行股权投资;就增加对Tellurian投资签署普通股购买协议
  13. android序列号怎么修改,修改Android序列号(Serial Number)
  14. 关于动漫的HTML网页设计作业——动漫网页(刀剑神域6个页面)
  15. Base64编解码及其C++实现
  16. dbf解析_DBF文件格式分析.doc
  17. (个人记录)安装pycocotools库出现Could not build wheels for pycocotools which use PEP 517 and cannot be install
  18. android https握手失败,Android SSL错误握手失败
  19. 怎么换头像啊。。。。。
  20. hadoop 历史版本下载

热门文章

  1. 项目经理问我Java内存区域模型!急急急
  2. android.mk ndk编译选项优化,Android NDK 编译脚本分析 之一
  3. 爬取猎聘python_爬取猎聘大数据岗位相关信息--Python
  4. 利用vector实现一对一(pair<int,int>)
  5. 7-10 石子合并 (10 分)
  6. [SpringBoot2]错误处理_默认规则
  7. [C++STL]list容器用法介绍
  8. [蓝桥杯2018初赛]乘积尾零-数论
  9. word文档相关使用
  10. 数据结构---多源最短路径