问题 A: 木棒根数

解法:把所有的情况保存下来,加一下就好

#include<bits/stdc++.h>
using namespace std;
map<char,int>q;
class P
{
public:
int cmd(string s)
{
int sum=;
for(int i=;i<s.length();i++)
{
sum+=q[s[i]];
}
return sum;
}
};
int main()
{
string s;
P solve;
q['']=;
q['']=;
q['']=;
q['']=;
q['']=;
q['']=;
q['']=;
q['']=;
q['']=;
q['']=;
q['+']=;
q['-']=;
q['=']=;
cin>>s;
cout<<solve.cmd(s)<<endl;
return ;
}

问题 B: 一个苹果都不给我

解法:三种情况,单独买,套装买,和混合买

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int n,m,p,q,ans[];
cin>>n>>m>>p>>q;
ans[]=n*m;
ans[]=n/p*q+(n%p)*m;
ans[]=(n/p+)*q;
sort(ans,ans+);
cout<<ans[]<<endl;
return ; }

问题 C: LED

解法:保存图形,然后xjb搞

include<stdio.h>
#include<string.h>
int main()
{
char num1[]={" _ _ _ _ _ _ _ _ "};
char num2[]={"| | | _| _||_||_ |_ ||_||_|"};
char num3[]={"|_| ||_ _| | _||_| ||_| _|"};
char str,a[]={"\0"};
int i,k,j,len;
scanf("%s",a);
len=strlen(a);
for(i=;i<len;++i)
{
j=a[i]-'';
k=j*;
printf("%c%c%c",num1[k],num1[k+],num1[k+]);
}
printf("\n");
for(i=;i<len;++i)
{
j=a[i]-'';
k=j*;
printf("%c%c%c",num2[k],num2[k+],num2[k+]);
}
printf("\n");
for(i=;i<len;++i)
{
j=a[i]-'';
k=j*;
printf("%c%c%c",num3[k],num3[k+],num3[k+]);
}
printf("\n");
return ;
}

问题 D: 路是自己选的

解法:应该都看出奇偶性关系了,一种是利用二进制,一种是二分,结果需要倒过来输出,所以使用了栈

#include<bits/stdc++.h>
using namespace std;
const int MAXN=;
int b[MAXN];
int main()
{
int x;
int a[];
scanf("%d",&x);
for(int i=;i<;i++)
{
scanf("%d",&a[i]);
b[a[i]]=i;
}
int u=b[x];
u=+u;
stack<char> s;
while(u!=)
{
if(u%==) s.push('L');else s.push('R');
u=u/;
}
while(!s.empty())
{
putchar(s.top());
s.pop();
}
puts("");
return ;
}

问题 E: All roads lead to rome

解法:标准解法是dp,然而可以用组合数学来做,也就是C(n,m)

#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n,m,l,r;
int a,b,c,d,ans=;
cin>>n>>m>>a>>b>>c>>d;
l=abs(a-c),r=abs(d-b);
for(int i=l+r;i>l;i--){
ans=ans*i/(l+r-i+);
}
cout<<ans<<endl;
}

问题 F: 找不到北

解法:求最短路最好利用bfs,当然dfs也能做到(一道基础的搜索题)

#include<bits/stdc++.h>
using namespace std;
int inf=(<<)-;
int Mx;
char m[][]={
"##########",
"#**#***#*#",
"#*#**##*##",
"#***##***#",
"##**#*#**#",
"#***#*#**#",
"#**#*****#",
"#****###*#",
"#***#**#*#",
"##########",
};
int a,b,c,d;
void dfs(int x,int y,int s)
{
if(m[x][y]=='#')
{
return;
}
else if(x==c&&y==d)
{
Mx=min(Mx,s);
}
s++;
m[x][y]='#';
dfs(x,y-,s);
dfs(x,y+,s);
dfs(x+,y,s);
dfs(x-,y,s);
m[x][y]='*';
}
int main()
{
int t;
cin>>t;
while(t--)
{
Mx=inf;
cin>>a>>b>>c>>d;
if(m[a][b]=='#'||m[c][d]=='#')
{
cout<<"-1"<<endl;
continue;
}
else if(a==c&&b==d)
{
cout<<""<<endl;
continue;
}
else
{
dfs(a,b,);
if(Mx==inf)
{
cout<<"-1"<<endl;
}
else
{
cout<<Mx<<endl;
}
}
}
return ;
}

2016年江西理工大学C语言程序设计竞赛(初级组)的更多相关文章

  1. 2018年江西理工大学C语言程序设计竞赛(初级组)一

     C语言竞赛初级组第一.二场答案:https://www.cnblogs.com/xingkongyihao/p/10046918.html  A: 逆序对 时间限制: 1 s      内存限制:  ...

  2. 2017年江西理工大学C语言程序设计竞赛(初级组)

    问题 A: Petr的盒子(初) #include <iostream> #include <stdio.h> #include <algorithm> using ...

  3. 2016年江西理工大学C语言程序设计竞赛(高级组)

    问题 A: jxust 解法:争议的问题(是输入整行还是输入字符串),这里倾向输入字符串,然后判断是否含有jxust就行 #include<bits/stdc++.h> using nam ...

  4. 2014江西理工大学C语言程序设计竞赛高级组题解

    1001 Beautiful Palindrome Number 枚举回文数字前半部分,然后判断该数字是否满足,复杂度为O(sqrt(n))! 1002 Recovery Sequence  本题的核 ...

  5. 2017年江西理工大学C语言程序设计竞赛(高级组)

    问题 A: 求近似值 #include <stdio.h> #include <time.h> #include <stdlib.h> using namespac ...

  6. 2018年江西理工大学C语言程序设计竞赛(高级组) 三角平方数

    题目描述 三角数:形如图a,圆点摆放成等边三角形的数字,则为三角数. (图a) 平方数:形如图b,小方块摆放成正方形的数字,则为平方数. (图b) 那么如果一个数字既是三角形数又是平方数,则称为三角平 ...

  7. 2018年江西理工大学C语言程序设计竞赛高级组部分题解

    B Interesting paths 考察范围:组合数学 此题是机器人走方格的变种,n*m的网格,从(1,1)走到(n,m),首先可以明确,水平要走m-1格,竖直要走n-1格,则走到目的地的任意一条 ...

  8. 2014江西理工大学C语言程序竞赛初级组

    坐公交 解法:略 #include<stdio.h> #include<string> #include<iostream> #include<math.h& ...

  9. 2015年江西理工大学C语言程序设计竞赛(高级组)

    A 解法:DP+二分 dp[i]=max(dp[i],dp[j]+p[i].v)(i>j) dp[i]表示建立i点之后能够获得的最大值 int n,M; struct node { int l, ...

随机推荐

  1. jquery ajax传递多个对象或数组到后台

    1.js对象创建:因为需要把对象json序列化后,才能传递到后台,后台根据json字符串进行反序列化. 2.Jquery   $.ajax方法的配置 针对$.ajax方法的配置参数需要进行修改: 1) ...

  2. 【HDU3721】枚举+最长路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3721 题意:给你一颗n个节点n-1条边的树,每条边都有一个权值,现在让你任意移动一条边然后把这条边连接 ...

  3. Sqlite 数据库出现database disk image is malformed报错的解决方法

    软件用的是Sqlite数据库,昨天还好好的,今天开机登录软件报错:database disk image is malformed 用Sqlite Expert Personal 重建索引,发现其中一 ...

  4. 常用SQLPLUS工具命令

    有两个   EMPNO ENAME          SAL的列标题 满   14行   为一个标题行 列行重叠了 虽然上述是修改了 linesize 的值,但是仍然没有改变 登录框的宽度,下面是修改 ...

  5. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(可持久化Trie)

    D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  6. javac编译、运行

    java源码(包结构) 源码存放位置:C:/Users/liaolongjun/DeskTop/java/ package test; import test.sub.F; public class ...

  7. mysql查询结果添加编号

    第一种方法: select   (@i:=@i+1)   as   i,table_name.*   from   table_name,(select   @i:=0)   as   it 第二种方 ...

  8. transform的用法和注意事项

    1.作用: 1)transform可以控制平移.比例缩放和旋转. 2)transform中的方法主要分为两种:带make和不带make的方法. 3)带make的方法主要是基于控件最初的状态进行改变,所 ...

  9. ps aux和ps -ef命令区别

      ps aux 是用BSD的格式来显示 java这个进程 显示的项目有:USER,PID,%CPU,%MEM,VSZ,RSS,TTY,STAT,START,TIME,COMMAND   ps -ef ...

  10. jquery例子

    jquery <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...