喵哈哈村的四月半活动(一)

题解:

唯一的case,就是两边长度一样的时候,第三边只有一种情况。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#define INF 1000000000
using namespace std;
const int MOD = 1234567;
int x,y;
int main()
{scanf("%d%d",&x,&y);double ans;if(x!=y){if(x<y)swap(x,y);ans=sqrt(x*x-y*y);printf("%.10f\n",ans);}ans=sqrt(x*x+y*y);printf("%.10f\n",ans);return 0;
}

喵哈哈村的四月半活动(二)

题解:拿一个map或者一个set,来统计这个数是否出现过即可。

#include<bits/stdc++.h>
using namespace std;set<int> S;
int main(){int n;scanf("%d",&n);for(int i=0;i<n;i++){int p;scanf("%d",&p);if(S.find(p)!=S.end()){cout<<"1";}else{cout<<"0";}S.insert(p);}cout<<endl;
}

喵哈哈村的四月半活动(三)

题解:转换一下题意,实际上就是问你从(x,y)到(1,1)的最短路是多少。

这个直接写个spfa就好了。

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#define INF 1000000000
using namespace std;
const int M = 510;
struct node
{int x,y;
}q[M*M*10];
int n,m,n1,m1;
int dx[5]={0,-1,0,1,0};
int dy[5]={0,0,1,0,-1};
int a[M][M],dis[M][M],flag[M][M];
void bfs(int x,int y)
{for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)dis[i][j]=INF;dis[x][y]=0;int l=0,r=0;q[++r].x=x;q[r].y=y;flag[x][y]=1;while(l!=r){l++;if(l>100010)l=1;node k=q[l];flag[k.x][k.y]=0;for(int i=1;i<=4;i++){node k1;k1.x=k.x+dx[i];k1.y=k.y+dy[i];if(k1.x>=1&&k1.x<=n&&k1.y>=1&&k1.y<=m){if(dis[k1.x][k1.y]>dis[k.x][k.y]+a[k1.x][k1.y]&&a[k1.x][k1.y]!=0){dis[k1.x][k1.y]=dis[k.x][k.y]+a[k1.x][k1.y];if(!flag[k1.x][k1.y]){flag[k1.x][k1.y]=1;r++;if(r>100010)r=1;q[r]=k1;}}}}}
}
int main()
{scanf("%d%d%d%d",&n,&m,&n1,&m1);for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);bfs(n1,m1);if(dis[1][1]==INF||a[1][1]==0){printf("-1\n");return 0;}printf("%d\n",dis[1][1]);return 0;
}

喵哈哈村的四月半活动(四)

题解:dp[i][j]表示当前还有i个节点,节点权值和为j的方案数是多少。

然后转移就好了。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<bitset>
#define MOD 10007
#define N 1010
#define M 1010
#define INF (1<<30)
using namespace std;
int n,m;
int mem[N][M];
int dp(int index,int val){if(index==1 && val>0) return 1;int tmp=0;for(int i=1;i<=val-index+1;i++){if(mem[index-1][val-i]==-1) mem[index-1][val-i]=dp(index-1,val-i);tmp=(tmp+mem[index-1][val-i])%MOD;}return tmp;
}
int main(){scanf("%d%d",&n,&m);memset(mem,-1,sizeof(mem));printf("%d",dp((m+1)/2,n));return 0;
}

喵哈哈村的四月半活动(五)

题解:暴力大模拟就好了。。。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<bitset>
#define INF (1<<30)
#define LEN 1010
#define L 1010
using namespace std;
char str[LEN];
char x[L];
char flag[1000];
char t[1000];
bool vis;
int main(){int n;scanf("%d",&n);vis=0;while(n--){if(vis) strcpy(flag,t);else scanf("%s",flag);if(strcmp(flag,"set")==0){scanf("%s",x);strcpy(str,x);vis=0;//      cout<<str<<endl;continue;}if(strcmp(flag,"add")==0){int a;scanf("%d%s",&a,x);char tmp[LEN];strcpy(tmp,str+a);strcpy(str+a,x);int len=strlen(x);strcpy(str+a+len,tmp);vis=0;//      cout<<str<<endl;continue;}if(strcmp(flag,"del")==0){int a;scanf("%d",&a);scanf("%s",t);char tmp[LEN];if(0<=t[0]-'0' && t[0]-'0'<=9){int len=strlen(t);int b=0;for(int i=0;i<len;i++) b=b*10+(t[i]-'0');if(a==b) {vis=0;continue;}if(a>b) swap(a,b);strcpy(tmp,str+b-1);strncpy(str,str,a);strcpy(str+a,tmp);vis=0;//      cout<<str<<endl;continue;}else {strcpy(tmp,str+a-1);strcpy(str,tmp);vis=1;//      cout<<str<<endl;continue;}}if(strcmp(flag,"rev")==0){reverse(str,str+strlen(str));vis=0;}//  cout<<str<<endl;}cout<<str<<endl;return 0;
}

转载于:https://www.cnblogs.com/qscqesze/p/6718677.html

喵哈哈村的魔法考试 Round #14 (Div.2) 题解相关推荐

  1. 喵哈哈村的魔法考试 Round #1 (Div.2) 题解源码(A.水+暴力,B.dp+栈)

    A.喵哈哈村的魔法石 发布时间: 2017年2月21日 20:05   最后更新: 2017年2月21日 20:06   时间限制: 1000ms   内存限制: 128M 描述 传说喵哈哈村有三种神 ...

  2. 喵哈哈村的魔法考试 Round #9 (Div.2) 题解

    A题 喵哈哈村的数据筛选游戏 题解:这道题签到题,拿个数组记录一下这个数是否出现过即可. #include<bits/stdc++.h> using namespace std; cons ...

  3. 喵哈哈村的魔法考试 Round #5 (Div.2) C

    喵哈哈村的狼人杀大战(4) 发布时间: 2017年3月6日 11:36   最后更新: 2017年3月6日 11:39   时间限制: 1000ms   内存限制: 128M 描述 喵哈哈村最近热衷于 ...

  4. 喵哈哈村的魔法考试 Round #10 (Div.2) B

    喵哈哈村与哗啦啦村的大战(二) 发布时间: 2017年3月27日 09:25   时间限制: 1000ms   内存限制: 128M 描述 喵哈哈村因为和哗啦啦村争夺稀有的水晶资源,展开了激烈的战斗. ...

  5. 喵哈哈村的魔法考试 Round #1 (Div.2) C 喵哈哈村的魔法石(II) 背包dp

    点击打开链接 描述 沈宝宝的天玄石做的又丑又难看,戴尔廖实在是看不下去了,于是就出手帮助了他. 戴尔廖从怀中掏出了很多块神奇的石头,这些石头都是矿石结晶.每颗矿石结晶拥有着的人之精华,以及的地之精华. ...

  6. 喵哈哈村的魔法考试 (1)

    描述 传说喵哈哈村有三种神奇的魔法石:第一种魔法石叫做人铁石,拥有$A$的能量:第二种魔法石叫做地冈石,拥有$B$的能量:而第三种,则是最神奇的天玄石,拥有无可比拟的$C$的能量! 但是有一天,沈宝宝 ...

  7. 玲珑学院OJ 1130 - 喵哈哈村的魔法大师╳灬兲笙疯癫°月【强连通+可相交最小路径覆盖+背包】

    1130 - 喵哈哈村的魔法大师╳灬兲笙疯癫°月 Time Limit:1s Memory Limit:256MByte Submissions:196Solved:23 DESCRIPTION ╳灬 ...

  8. 喵哈哈村的魔法源泉(3)-(树的直径)

    喵哈哈村的魔法源泉(3) 发布时间: 2017年5月9日 20:59   最后更新: 2017年5月9日 20:59   时间限制: 1000ms   内存限制: 128M 描述 喵哈哈村有一个魔法源 ...

  9. Codeforces Round #514 (Div. 2)题解

    Codeforces Round #514 (Div. 2)题解 A 喵,直接模拟. B 枚举所有盖章时的,合法的,左上角的位置.能盖的话就盖一下.最后check一下图案是否相等即可 C 一轮一轮的扔 ...

  10. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

最新文章

  1. hive动态分区shell_Hive动态分区 参数配置及语法
  2. lamda表达式 随机取数据的方法
  3. 在c语言中错误的常数表示是,C语言程序设计试题
  4. vue+element+echarts柱状图+列表
  5. 重学前端学习笔记(八)--JavaScript中的原型和类
  6. Scite 中文支持
  7. java哈喽word,JavaWeb之HelloWord
  8. 2017.9.5 组合数学 思考记录
  9. 【JAVASCRIPT】如何不使用jquery函数和ajax框架实现ajax效果
  10. Leetcode: Excel Sheet Column Number
  11. xlc mysql_mysql – 用于存储产品信息的noSQL?
  12. Mac Android studio: Gradle Build Running 、 run build 运行卡顿 、 加载慢问题问题(亲测可用)
  13. Node.js:中间件——配置静态资源中间件
  14. USACO26 moofest 奶牛集会(归并排序)
  15. 读书篇:《细说PHP》一、简介
  16. 清华大学计算机科学与技术考研分数,清华大学计算机科学与技术系2020考研复试分数线...
  17. 私服玉兔元素服务器在哪个网站,1.85玉兔元素服务端
  18. 排序算法lowB三人组
  19. C#开发WinForm之DataGridView开发
  20. Android--Recovery模块之恢复出厂设置

热门文章

  1. Form窗体点击关闭按钮并未关闭进程的解决方法
  2. 最全的Discuz! x2去除forum.php尾巴的方法
  3. printk与日志优先级设置
  4. 转载 java序列化与反序列化
  5. C#对象的浅拷与深拷贝
  6. 第一个mybatis项目
  7. org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state wo
  8. js 操作java对象_[Java教程]js 对象操作 对象原型操作 把一个对象A赋值给另一个对象B 并且对象B 修改 不会影响 A对象...
  9. Vue3:集成wangEditor富文本编辑器
  10. React:AntDesign引入简介