喵哈哈村的魔法考试 Round #14 (Div.2) 题解
喵哈哈村的四月半活动(一)
题解:
唯一的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) 题解的更多相关文章
- 喵哈哈村的魔法考试 Round #2 (Div.2) 题解
喵哈哈村的魔法考试 Round #2 (Div.2) 题解 A.喵哈哈村的战争 题解: 这道题就是for一遍,统计每个村子的战斗力的和,然后统计哪个村子的战斗力和大一点就好了. 唯一的坑点,就是这道题 ...
- 喵哈哈村的魔法考试 Round #1 (Div.2) 题解
喵哈哈村的魔法考试 Round #1 (Div.2) 题解 特别感谢出题人,qscqesze. 也特别感谢测题人Xiper和CS_LYJ1997. 没有他们的付出,就不会有这场比赛. A 喵哈哈村的魔 ...
- 喵哈哈村的魔法考试 Round #7 (Div.2) 题解
喵哈哈村的魔法考试 Round #7 (Div.2) 注意!后四道题来自于周日的hihocoder offer收割赛第九场. 我建了个群:欢迎加入qscoj交流群,群号码:540667432 大概作为 ...
- 喵哈哈村的魔法考试 Round #1 (Div.2) 题解&源码(A.水+暴力,B.dp+栈)
A.喵哈哈村的魔法石 发布时间: 2017年2月21日 20:05 最后更新: 2017年2月21日 20:06 时间限制: 1000ms 内存限制: 128M 描述 传说喵哈哈村有三种神 ...
- 喵哈哈村的魔法考试 Round #19 (Div.2) 题解
题解: 喵哈哈村的魔力源泉(1) 题解:签到题. 代码: #include<bits/stdc++.h> using namespace std; int main(){ long lon ...
- 喵哈哈村的魔法考试 Round #4 (Div.2) 题解
有任何疑问,可以加我QQ:475517977进行讨论. A 喵哈哈村的嘟嘟熊魔法(1) 题解 这道题我们只要倒着来做就可以了,因为交换杯子是可逆的,我们倒着去模拟一遍就好了. 有个函数叫做swap(a ...
- 喵哈哈村的魔法考试 Round #20 (Div.2) 题解
题解: A 喵哈哈村的跳棋比赛 题解:其实我们要理解题意就好了,画画图看看这个题意.x<y,那么就交换:x>y,那么x=x%y. 如果我们经过很多次,或者y<=0了,那么就会无限循环 ...
- 喵哈哈村的魔法考试 Round #18 (Div.2) 题解
喵哈哈村的古怪石碑(一) 题解:暴力check一下是等比数列还是等差数列,然后输出答案即可.注意如果数据范围是1e9的话,就要快速幂了. 代码: #include <cstdio> #in ...
- 喵哈哈村的魔法考试 Round #13 (Div.2) 题解
喵哈哈村的木星传说(一) 旋转90°,找找规律就知道(x,y)->(n-1-y,x) 然后输出就好了. #include<bits/stdc++.h> using namespace ...
随机推荐
- PNG,JPEG,BMP,JIF图片格式详解及其对比
原文地址:http://blog.csdn.net/u012611878/article/details/52215985 图片格式详解 不知道大家有没有注意过网页里,手机里,平板里的图片,事实上,图 ...
- zabbix3.0.4添加对指定进程的监控
zabbix3.0.4添加对进程的监控: 主要思路: 通过 ps -ef|grep sdk-push-1.0.0.jar |grep -v grep|wc -l 这个命令来判断进程sdk-push是否 ...
- listener failed: zbx_tcp_listen() fatal error: unable to serve on any address [[-]:20050]
故障现象: 客户端报错:service zabbix-agent 启动后,端口没有被正常监听,服务端也无法正常连接 将客户端改为二进制文件安装也不能正常启动/usr/local/zabbix/sbin ...
- openvpn用户管理、linux客户端配置及企业常用真实案例解析
1.给企业用户分配VPN账户的流程: 添加拨号需要密码的用户 # source vars NOTE: If you run ./clean-all, I will be doing a rm -rf ...
- Android开发之深入理解Android Studio构建文件build.gradle配置
摘要: 每周一次,深入学习Android教程,TeachCourse今天带来的一篇关于Android Studio构建文件build.gradle的相关配置,重点学习几个方面的内容:1.applica ...
- 关系操作符 < > = == <= >= !=
基本类型可以用所有的操作符 对象要用equal eqauls() //用法 System.out.println(v1.equals(v2)); JAVA学习(二) STRING使用EQUALS方法和 ...
- 对以内部 git 仓库为 composer 依赖的 package,加上版本号
现实问题 之前同事做了一个 composer package,做为公司大量 laravel 项目的通用模块. 但是,在实际使用中,每个项目对改 package 的依赖版本是有所不同的.否则 compo ...
- JavaStrip和python的变量存储位置
<script> var a =1 function a() { console.log("sdfdsf") } a() </script> Uncaugh ...
- python接口自动化测试二十:函数写接口测试
# coding:utf-8import requestsimport refrom bs4 import BeautifulSoup # s = requests.session() # 全局的s ...
- Python 多环境配置管理
一.概述 实际工程开发中常常会对开发.测试和生产等不同环境配置不同的数据库环境,传统方式可以通过添加不同环境的配置文件达到部署时的动态切换的效果.这种方式还不错,不过不同环境间往往会共享相同的配置而造 ...