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

题解:

唯一的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;
}

喵哈哈村的魔法考试 Round #14 (Div.2) 题解的更多相关文章

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

    喵哈哈村的魔法考试 Round #2 (Div.2) 题解 A.喵哈哈村的战争 题解: 这道题就是for一遍,统计每个村子的战斗力的和,然后统计哪个村子的战斗力和大一点就好了. 唯一的坑点,就是这道题 ...

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

    喵哈哈村的魔法考试 Round #1 (Div.2) 题解 特别感谢出题人,qscqesze. 也特别感谢测题人Xiper和CS_LYJ1997. 没有他们的付出,就不会有这场比赛. A 喵哈哈村的魔 ...

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

    喵哈哈村的魔法考试 Round #7 (Div.2) 注意!后四道题来自于周日的hihocoder offer收割赛第九场. 我建了个群:欢迎加入qscoj交流群,群号码:540667432 大概作为 ...

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

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

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

    题解: 喵哈哈村的魔力源泉(1) 题解:签到题. 代码: #include<bits/stdc++.h> using namespace std; int main(){ long lon ...

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

    有任何疑问,可以加我QQ:475517977进行讨论. A 喵哈哈村的嘟嘟熊魔法(1) 题解 这道题我们只要倒着来做就可以了,因为交换杯子是可逆的,我们倒着去模拟一遍就好了. 有个函数叫做swap(a ...

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

    题解: A 喵哈哈村的跳棋比赛 题解:其实我们要理解题意就好了,画画图看看这个题意.x<y,那么就交换:x>y,那么x=x%y. 如果我们经过很多次,或者y<=0了,那么就会无限循环 ...

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

    喵哈哈村的古怪石碑(一) 题解:暴力check一下是等比数列还是等差数列,然后输出答案即可.注意如果数据范围是1e9的话,就要快速幂了. 代码: #include <cstdio> #in ...

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

    喵哈哈村的木星传说(一) 旋转90°,找找规律就知道(x,y)->(n-1-y,x) 然后输出就好了. #include<bits/stdc++.h> using namespace ...

随机推荐

  1. PNG,JPEG,BMP,JIF图片格式详解及其对比

    原文地址:http://blog.csdn.net/u012611878/article/details/52215985 图片格式详解 不知道大家有没有注意过网页里,手机里,平板里的图片,事实上,图 ...

  2. cactiez v11添加对mysql数据库、apache系统进行监控

    cactiez默认已经安装了mysql监控的模板,需要我们对服务器端和被监控的mysql客户端进行配置才能生效. 被监控的Mysql客户端: 如cactiez的IP为192.168.0.8 #添加一个 ...

  3. 源码编译安装nginx1.4.7

    传统上基于进程或线程模型架构的web服务通过每进程或每线程处理并发连接请求,这势必会在网络和I/O操作时产生阻塞,其另一个必然结果则是对内存或CPU的利用率低下.生成一个新的进程/线程需要事先备好其运 ...

  4. wap页面缩放

    html{font-size: 100%;}.in-main{ min-width:320px; max-width:640px; margin:0 auto; font-size:14px; bac ...

  5. LeetCode(36): 有效的数独

    Medium! 题目描述: 判断一个 9x9 的数独是否有效.只需要根据以下规则,验证已经填入的数字是否有效即可. 数字 1-9 在每一行只能出现一次. 数字 1-9 在每一列只能出现一次. 数字 1 ...

  6. pytest三:fixture_conftest.py 自定义测试用例的预置条件(setup)

    用例加 setup 和 teardown 可以实现在测试用例之前或之后加入一些操作,但返种是整个脚本全局生效的,如果我想实现以下场景:用例 1 需要先登录,用例 2 不需要登录,用例 3 需要先登录. ...

  7. python+selenium六:等待相关

    显式等待(sleep): 固定的等待(死等),不管页面有没有加载完,都等设置的时间过了再做下一步操作 隐式等待 全局生效,只写一次即可(仅当前页面),缺点:如果页面一直转圈,如:js出错将等待到所设置 ...

  8. CSS 滤镜

    声明: web前端学习笔记,欢迎大神指点.联系QQ:1522025433. CSS样式表是一种为超文本标签语言提供增强补充服务的技术,可对每一个html的标签做精雕细刻的修饰.只用html制作的网页, ...

  9. 《剑指offer》-数组中出现次数超过一半的数字

    /* 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2.如果 ...

  10. 线程池 多线程运行结束后 如何关闭? ExecutorService的正确关闭方法

    前言 最近在使用ExecutorService的时候,对于与ExecutorService相关的概念有些迷糊, 加上本身ExecutorService内部的有些方法名在取名上也容易让使用者误解,导致 ...