2014江西理工大学C语言程序竞赛高级组
Beautiful Palindrome Number
题意:求N里面有多少个符合要求的数字(数字要求:回文数,且前一半部分是不严格递增)
解法:打表
#include<bits/stdc++.h>
using namespace std;
int find1(int index)
{
int count1 = ;
int number = ; //记录数位上的回文数,如个位回文数为9
int w = ; //记录数位 long half; //保存回文数的左半边的结果
long h = ; //回文数的左半边的起始基数
long res; //结果 while(true)
{
if(w > && w% == ) //每进两个数位,回文数乘以10
{
number *= ;
}
w++; //数位加一
if(count1 + number > index) //回文数大于查找的回数,跳出
break; count1+= number; //回文数加上当前数位上的回文数
} index -= count1; //在当前数位上的位置。如w=5,index=50,则万位上的第50个回文数是我们所求 for(int i = ; i < (w-) / ; i++) //求回文数的左半边的基数,如回文数在万位上,则为100
{
h *= ;
} half = h + index; //回文数的左半边,如100 + 50 = 150 res = half; if(w% != ) //如果为奇数,则中间那个数不必算入右半边了!
half /=; while(half != ) //拼接回文数
{
res = res * + half % ;
half /= ;
} return res;
}
int cmd(int x)
{
int cot=;
int a[];
while(x)
{
a[cot++]=x%;
x/=;
}
int pos=a[];
if(cot%==)
{
for(int i=; i<cot/; i++)
{
if(pos<=a[i])
{
pos=a[i];
}
else
{
return ;
}
}
}
else
{
for(int i=; i<=cot/; i++)
{
if(pos<=a[i])
{
pos=a[i];
}
else
{
return ;
}
}
} return ;
}
int a[]={,, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
,};
int main()
{
int t;
int n;
cin>>t;
while(t--)
{
cin>>n;
for(int i=;;i++)
{
if(a[i]==) break;
else if(a[i]>n)
{
cout<<i<<endl;
break;
}
}
}
return ;
}
五子棋
解法:其实不难,判断却非常复杂,首先当然只要判断是否成为5子。然后判断黑白棋的个数是否满足要求,接下来判断是白子后下还是黑子后下。再根据这两种情况判断,具体看代码判断
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int ans[][];
//int n,m,a,b;
int Min=(1e9);
string a[];
int x1,x2,x3,x4,x5,x6,x7,x8;
int cmd(char s)
{
int M=-;
for(int i=; i<; i++)
{ for(int j=; j<; j++)
{
x1=,x2=,x3=,x4=,x5=,x6=,x7=,x8=;
if(a[i][j]==s)
{
//cot1++;
// cout<<"/"<<endl;
int ans1=i;
int ans2=j;
while(ans1>=)
{
if(a[ans1][j]==s)
{
// a[i][ans2]='.';
ans1--;
x1++;
}
else
{
break;
}
}
// cout<<x1<<"A"<<endl;
ans1=i;
ans2=j;
//cout<<ans1<<" "<<ans2<<endl;
while(ans1<)
{
if(a[ans1][j]==s)
{
// a[ans1][j]='.';
ans1++;
x2++;
}
else
{
break;
}
}
// cout<<x2<<"B"<<endl;
ans1=i;
ans2=j;
while(ans2>=)
{
if(a[i][ans2]==s)
{
// a[i][ans2]='.';
ans2--;
x3++;
}
else
{
break;
}
}
// cout<<x3<<"C"<<endl;
ans1=i;
ans2=j;
while(ans2<)
{
// cout<<i<<" "<<ans2<<endl;
// cout<<a[i][ans2]<<endl;
if(a[i][ans2]==s)
{
// cout<<"A"<<endl;
// a[i][ans2]='.';
ans2++;
x4++;
}
else
{
break;
}
}
//cout<<x4<<"D"<<endl;
ans1=i;
ans2=j;
while(ans1>=&&ans2>=)
{
if(a[ans1][ans2]==s)
{
// a[ans1][ans2]='.';
ans1--;
ans2--;
x5++;
}
else
{
break;
}
}
//cout<<x5<<endl;
ans1=i;
ans2=j;
while(ans1<&&ans2<)
{
if(a[ans1][ans2]==s)
{
// a[ans1][ans2]='.';
ans1++;
ans2++;
x6++;
}
else
{
break;
}
}
//cout<<x6<<endl;
ans1=i;
ans2=j;
while(ans1>=&&ans2<)
{
if(a[ans1][ans2]==s)
{
// a[ans1][ans2]='.';
ans1--;
ans2++;
x7++;
}
else
{
break;
}
}
// cout<<x7<<endl;
ans1=i;
ans2=j;
while(ans1<&&ans2>=)
{
if(a[ans1][ans2]==s)
{
//a[ans1][ans2]='.';
ans1++;
ans2--;
x8++;
}
else
{
break;
}
}
// cout<<x1<<" "<<x2<<endl;
// cout<<x3<<" "<<x4<<endl;
// cout<<x5<<" "<<x6<<endl;
// cout<<x7<<" "<<x8<<endl;
//cout<<x8<<endl;
M=max({x1+x2-,x3+x4-,x5+x6-,x7+x8-,M});
} }
// M=-1;
}
if(M>=)
{
return ;
}
else
{
return ;
}
}
int cmp(char s)
{
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
if(a[i][j]==s)
{
a[i][j]='.';
for(int k=; k<; k++)
{
//cout<<a[k]<<endl;
}
// cout<<cmd(s)<<endl;
if(!cmd(s))
{
return ;
}
// cout<<endl;
a[i][j]=s;
}
}
}
return ;
}
int main()
{ int t;
cin>>t;
while(t--)
{
x1=,x2=,x3=,x4=,x5=,x6=,x7=,x8=;
int M=-;
int cot1=;
int cot2=;
int N=-;
for(int i=; i<; i++)
{
cin>>a[i];
for(int j=; j<; j++)
{
if(a[i][j]=='@')
{
cot1++;
}
else if(a[i][j]=='X')
{
cot2++;
}
}
}
if(cot2==cot1+ || cot1 == cot2)
{
int wb = cmd('X');
int ww = cmd('@');
if(cot2==cot1+ && wb)
{
if(ww)
cout << "wrong state" << endl;
else
{
if(cmp('X'))cout << "black" << endl;
else cout << "wrong state" << endl;
}
}
else if(ww && cot1 == cot2)
{
if(wb)
cout << "wrong state" << endl;
else
{
if(cmp('@'))cout << "white" << endl;
else cout << "wrong state" << endl;
}
}
else if(!wb && !ww)cout << "continue" << endl;
else cout << "wrong state" << endl;
}
else cout << "wrong state" << endl;
}
return ;
}
丁丁历险记
解法:数据不大,跑最短路,再求1-A到A+B哪一个更短
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int ans[][];
int n,m,a,b;
int Min=(1e9);
int main()
{
int t;
cin>>t;
while(t--)
{
for(int i=; i<=; i++)
{
for(int j=; j<=; j++)
{
ans[i][j]=Min;
}
}
cin>>a>>b>>m;
for(int i=;i<=m;i++)
{
int s,e;
cin>>s>>e;
if(s!=e)
{
ans[s][e]=;
ans[e][s]=;
}
ans[s][s]=;
ans[e][e]=;
}
for(int k=; k<=a+b; k++)
{
for(int i=; i<=a+b; i++)
{
for(int j=; j<=a+b; j++)
{
ans[i][j]=min(ans[i][j],ans[i][k]+ans[k][j]);
}
}
}
int M=(1e9);
for(int i=;i<=a;i++)
{
M=min(ans[i][a+b],M);
}
if(M==(1e9))
{
puts("No");
}
else
cout<<M<<endl;
}
return ;
}
平行四边形
解法:数学,重点是知道a,b,c,d是干什么的
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int n;
int t;
cin>>t;
while(t--)
{
int a,b,c,d;
int sum=;
cin>>a>>b>>c>>d;
for(int i=;i<d;i++)
{
if(i*c%d==)
{
sum+=b-;
}
else
{
sum+=b;
}
}
cout<<sum<<endl;
}
return ;
}
木木换班
解法:结构体排序
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct P
{
int a,b;
}He[];
bool cmd(P x,P y)
{
if(x.b==y.b)
{
return x.a<y.a;
}
return x.b>y.b;
}
int main()
{
int t;
int n;
cin>>t;
while(t--)
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>He[i].a>>He[i].b;
}
sort(He+,He+n+,cmd);
for(int i=;i<=n;i++)
{
// cout<<He[i].a<<" "<<He[i].b<<endl;
}
cout<<He[].a+He[].b<<endl;
}
return ;
}
0.333333333......
解法:a*100000....%b然后xjb求
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
double a,b;
cin>>a>>b;
double s=a/b*1.0;
s*=;
// cout<<s<<endl;
ll s1=(ll)s;
// cout<<s1<<endl;
if(abs(s1-s)<=1e-)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
// printf("[%d,%d]\n",a-1,b-1);
}
return ;
}
定义域
解法:没啥好说的
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int a,b;
cin>>a>>b;
printf("[%d,%d]\n",a-,b-);
}
return ;
}
2014江西理工大学C语言程序竞赛高级组的更多相关文章
- 2014江西理工大学C语言程序竞赛初级组
坐公交 解法:略 #include<stdio.h> #include<string> #include<iostream> #include<math.h& ...
- 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格,则走到目的地的任意一条 ...
- 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 ...
- 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, ...
随机推荐
- 进击的java - tomcat的安装,配置都正确之后,还是报错
1.问题 配置Apatch Tomcat过程报错: The CATALINA_HOME environment variable is not defined correctly.This envir ...
- CCF真题之最大矩形
201312-3 问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ i ≤ n)个矩形的高度是hi.这n个矩形构成了一个直方图.例如,下图中六个矩形的高度就分别是3, 1, 6 ...
- Demo12SimpleAdapter
/Users/alamps/AndroidStudioProjects/Demo12SimpleAdapter/Demo12SimpleAdapter/src/main/res/layout/data ...
- 技术总监和CTO的区别 浅谈CTO的作用----软件公司如何开源节流(一)[转]
我一直在思考软件公司如何开源节流.当然,老板也在思考开源节流.当然,老板思考的开源节流在公司运营层面上,而我作为CTO,我考虑的则是在产品运营角度上来思考这个问题.否则,一个软件公司,它的生存与发展就 ...
- 目前主流的国产WebApp框架
1.FrozenUI:QQ 2.WeUI:WeChat 3.SUI:Taobao
- "服务器 '' 上的 MSDTC 不可用。"
调试程序的时候,出现异常消息“The underlying provider failed on Open”: 详细信息:和{"服务器 '' 上的 MSDTC 不可用."}: 网上 ...
- 项目中的一个JQuery ajax实现案例
/** * brief 这些代码用于在线制图中 attention author <list of authors> <date> begin modify by * nu ...
- TI CC254x BLE教程 1
约定, 第一次翻译这种东西, 专有名词的翻译原则还是不太清楚, 总之涉及有可能误解的词, 都用双语, 如果是简单的, 直接英文或者中文, 取决于我是否能找到中文合适的词来翻译. 何为BLE: 1. 是 ...
- sersync实现触发式同步
金山的一个居于inotify+rsync进行二次开发实现文件同步的小工具sersync,能够很方便的实现文件触发式同步 Inotify 是基于inode级别的文件系统监控技术,是一种强大的.细粒度的. ...
- Makefile学习之make 的运行【转】
转自:http://blog.csdn.net/suzilong11/article/details/7852830 —————— 一般来说,最简单的就是直接在命令行下输入make命令,make命令会 ...