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

题解:

唯一的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. Html5 序列帧动画

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  2. centos系统初始化流程及实现系统裁剪

    Linux系统的初始化流程: POST:ROM+RAM BIOS: Boot Sequence MBR: 446:bootloader 64: 分区表 2: 5A kernel文件:基本磁盘分区 /s ...

  3. sklearn.model_selection模块

    后续补代码 sklearn.model_selection模块的几个方法参数

  4. redhat5 设置静态ip

    Last login: Sat Oct 14 16:19:13 2017 # 进入ip凭证文件设置地方 [root@oracle ~]# cd /etc/sysconfig/network-scrip ...

  5. TestNG测试方法

    @Test(enabled = false)有助于禁用此测试用例. 分组测试是TestNG中的一个新的创新功能,使用<groups>标记在testng.xml文件中指定分组. 它可以在&l ...

  6. poj3468

    #include<iostream> #include<cstring> #include<cstdio> using namespace std; #define ...

  7. 步步为营-68-asp.net简单练习(get set)

    1 加法计算器 using System; using System.Collections.Generic; using System.Linq; using System.Text; using ...

  8. Ext.js中自己扩展的EasyGrid

    这里只写了一些核心的代码,具体如下: Ext.ux.EasyGrid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { t ...

  9. hdu 3405 删掉某点后 求最小生成树

    给出N个点的坐标 边的权值为两点间的距离 删掉其中某点 求最小生成树的权值和 要求这权值最小 因为最多50个点 所以具体是删哪个点 用枚举假如有4个点 就要求4次最小生成树 分别是2 3 4 | 1 ...

  10. hdu 4707 仓鼠 记录深度 (BFS)

    题意:linji的仓鼠丢了,他要找回仓鼠,他在房间0放了一块奶酪,按照抓鼠手册所说,这块奶酪可以吸引距离它D的仓鼠,但是仓鼠还是没有出现,现在给出一张关系图,表示各个房间的关系,相邻房间距离为1,而且 ...