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

题解:

唯一的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. 转载:2.2.2 配置项的语法格式《深入理解Nginx》(陶辉)

    原文:https://book.2cto.com/201304/19627.html 从上文的示例可以看出,最基本的配置项语法格式如下: 配置项名 配置项值1 配置项值2 - ; 下面解释一下配置项的 ...

  2. Jenkins构建次数设置

    Build after other projects are built:在其他项目触发的时候触发,里面有分为三种情况,也就是其他项目构建成功.失败.或者不稳定的时候触发项目: Poll SCM:定时 ...

  3. python安装虚拟环境pipenv

    python里如果多个多个项目同时引用包,就会涉及到包版本的问题,包不同版本管理的问题可以用虚拟环境来管理, 创建虚拟环境,这里是用官方推荐的pipenv来创建 先用pip命令行安装pipenv pi ...

  4. PYTHON-网络通信 TCP

    网络编程: 学习网络编程 为什么?目的: 服务端特点: 网络通讯(通信) 什么是网络通讯? 为什么?目的:网络建立的目的是为数据交互(通信) 如何实现通讯(通信)? 互联网协议 互联网=物理连接介质+ ...

  5. Luogu P4945 【最后的战役】

    本来以为做法一样,就是少带个$log$,结果发现看不懂出题人的题解(我好菜啊) 那就自己写一篇吧 比较简单的$DP$思路 状态定义: 前两个转移很好处理,第三个好像就不好办了 不妨暴力定义进状态里 设 ...

  6. pytest七:assert断言

    断言是写自动化测试基本最重要的一步,一个用例没有断言,就失去了自动化测试的意义了.什么是断言呢?简单来讲就是实际结果和期望结果去对比,符合预期那就测试 pass,不符合预期那就测试 failed py ...

  7. python接口自动化测试二十一:类和方法

    # 类和方法 class Count(): def __init__(self, aaa, bbb): # 初始化 # 可以放公共的参数 print('实例化的时候,会执行init的内容') self ...

  8. 使用匿名内部类调用start方法

    package chapter03;//类实现接口public class WD implements Runnable{//重写接口的方法 @Override public void run() { ...

  9. 安装httpd过程,将网站部署到httpd过程

    1,配置DNSvi /etc/resolv.conf 加入以下代码 nameserver 192.168.0.1 nameserver 8.8.8.8 nameserver 8.8.4.4 2.输入y ...

  10. bootstrap——辅助类和响应式工具类

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...