2016年江西理工大学C语言程序设计竞赛(初级组)
问题 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语言程序设计竞赛(初级组)的更多相关文章
- 2018年江西理工大学C语言程序设计竞赛(初级组)一
C语言竞赛初级组第一.二场答案:https://www.cnblogs.com/xingkongyihao/p/10046918.html A: 逆序对 时间限制: 1 s 内存限制: ...
- 2017年江西理工大学C语言程序设计竞赛(初级组)
问题 A: Petr的盒子(初) #include <iostream> #include <stdio.h> #include <algorithm> using ...
- 2016年江西理工大学C语言程序设计竞赛(高级组)
问题 A: jxust 解法:争议的问题(是输入整行还是输入字符串),这里倾向输入字符串,然后判断是否含有jxust就行 #include<bits/stdc++.h> using nam ...
- 2014江西理工大学C语言程序设计竞赛高级组题解
1001 Beautiful Palindrome Number 枚举回文数字前半部分,然后判断该数字是否满足,复杂度为O(sqrt(n))! 1002 Recovery Sequence 本题的核 ...
- 2017年江西理工大学C语言程序设计竞赛(高级组)
问题 A: 求近似值 #include <stdio.h> #include <time.h> #include <stdlib.h> using namespac ...
- 2018年江西理工大学C语言程序设计竞赛(高级组) 三角平方数
题目描述 三角数:形如图a,圆点摆放成等边三角形的数字,则为三角数. (图a) 平方数:形如图b,小方块摆放成正方形的数字,则为平方数. (图b) 那么如果一个数字既是三角形数又是平方数,则称为三角平 ...
- 2018年江西理工大学C语言程序设计竞赛高级组部分题解
B Interesting paths 考察范围:组合数学 此题是机器人走方格的变种,n*m的网格,从(1,1)走到(n,m),首先可以明确,水平要走m-1格,竖直要走n-1格,则走到目的地的任意一条 ...
- 2014江西理工大学C语言程序竞赛初级组
坐公交 解法:略 #include<stdio.h> #include<string> #include<iostream> #include<math.h& ...
- 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, ...
随机推荐
- 前端技术-PS切图
页面制作部分之PS切图 <--本标签下,通过页面制作.页面架构.javascript程序设计.DOM编程艺术.产品前端架构五部分来分享总结笔记,总结笔记会陆续分享--> 网页设计在技术层面 ...
- 使用JDBC批量保存数据(JdbcDaoSupport,JdbcTemplete)
最近做的一个项目中用到了Hibernate的,然后数据库批量插入数据的时候就使用到了hibernate的批处理,但是效率比较低,看网上说还有一些限制,要禁止二级缓存,还要多一个batch_size的配 ...
- IP地址的分类与寻址
IP地址:有一种标识符,被TCP/IP协议簇的IP层用来标识 连接到因特网的设备.IP协议的第4版IPv4地址是32位地址,是连接地址,定义了每一个连接到因特网上的设备(可以认为是主机的别名),而不是 ...
- js 闭包的简单理解
let a = function(){ var i=0; let b = function(){ i++; alert(i); } return b; } let c = a(); c(); 这段代码 ...
- 玩坏JVM很简单--toString的递归调用
在JVM的内存管理机制下很少发生内存溢出的情况.至少我碰见的少,好像在SSH我多次发布项目时候出现过一次.今天看见一个特简单的方法让内存溢出(好吧,我似乎作死了--!): public class I ...
- C# Datatable排序
在C#中要对Datatable排序,可使用DefaultView的Sort方法.先获取Datatable的DefaultView,然后设置 得到的Dataview的sort属性,最后用视图的ToTab ...
- EmguCV 简单图形绘制
一.圆 public static void cvCircle( IntPtr img, System.Drawing.Point center, //Center of the circle int ...
- python 安装 twisted 库
pip 安装twisted库需要先安装依赖包,不然报"error: command 'gcc' failed with exit status 1" # yum install g ...
- Cannot create a server using the selected type.
1.退出 eclipse 2.到[工程目录下]/.metadata/.plugins/org.eclipse.core.runtime 3.把org.eclipse.wst.server.core.p ...
- 导入TDP数据包备份
package org.alfresco.repo.bom.util; import java.io.BufferedReader; import java.io.File; import java. ...