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

题解:

唯一的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. 【转】Visual Studio——多字节编码与Unicode码

    多字节字符与宽字节字符 1) char与wchar_t 我们知道C++基本数据类型中表示字符的有两种:char.wchar_t. char叫多字节字符,一个char占一个字节,之所以叫多字节字符是因为 ...

  2. listener failed: zbx_tcp_listen() fatal error: unable to serve on any address [[-]:20050]

    故障现象: 客户端报错:service zabbix-agent 启动后,端口没有被正常监听,服务端也无法正常连接 将客户端改为二进制文件安装也不能正常启动/usr/local/zabbix/sbin ...

  3. 使用linux计划任务自动拉起停止的通达OA服务apache和mysql服务

    概述: 数据库或web服务器瞬时并发过大时,可能面临宕机的危险,用类似开门狗的程序自动监控程序是否正常运行,在服务停止时自动启动服务,可临时解决该问题 监控apache服务的脚本: 每两分钟执行脚本检 ...

  4. SQL中的 if 结构和循环(while)结构

  5. notepad++ 快捷键大全、notepad常用快捷键

    Notepad++ 快捷键 大全, notepad++也情有独钟,最近发现了一个快捷键,就是选中单词,ctrl+shift+enter.不过现在想知道一个快捷键,假设有三行代码,选中后一般按TAB就可 ...

  6. Java 企业级 JavaEE

    授权协议:CDDL 开发语言:Java 操作系统:跨平台 开发厂商:Oracle 原文:https://www.oschina.net/p/j2ee Java EE 详细介绍 这是SUN公司推出的J2 ...

  7. 【docker】资料

    https://yeasy.gitbooks.io/docker_practice/content/network/linking.html

  8. laravel console - 自定义命令

    在改造一个支付流程,新的流程加入了一个新的数据表字段,但是这个新的字段需要通过计算来填充,所以为了兼容历史数据,必须将已有的数据行重新计算一遍该字段. 这时使用 laravel console 命令就 ...

  9. 《必须知道.NET》3.OO之美

    3.2 依赖的哲学 3.2.1 本质诠释 "不要调用我们,我们会调用你" 3.2.2 什么是依赖,什么是抽象 "耦合是不可避免的" (1)什么是依赖和耦合 依赖 ...

  10. hdu 2066 多起点 多终点

    多起点 多终点 无向图 结点的个数要自己求 Sample Input6 2 3 //边数 起点数 终点数1 3 5 //u v w1 4 72 8 123 8 44 9 129 10 21 2 //起 ...