A

解法:DP+二分

dp[i]=max(dp[i],dp[j]+p[i].v)(i>j)

dp[i]表示建立i点之后能够获得的最大值

int n,M;

struct node
{
int l,v;
}p[];
int dp[]; bool cmp(node a,node b){
return a.l < b.l;
} bool judge_oo(){
int Max = -;
for(int i = ;i <= n;i++) Max = max(Max,p[i].v);
if(Max >= M) return ;
return ;
} bool judge_no(){
int sum = ;
for(int i = ;i <= n;i++) sum += p[i].v;
if(sum >= M) return ;
return ;
} bool judge_DP(int L){
memset(dp,,sizeof dp);
for(int i = ;i <= n;i++){
for(int j = ;j < i; j++){
if(p[i].l - p[j].l >= L){
dp[i] = max(dp[i],dp[j] + p[i].v);
}
}
}
int ML = ;
for(int i = ;i <= n;i++) ML = max(ML,dp[i]);
if(ML >= M) return ;
return ;
} int solve(int L,int R){
while(L + < R){
int mid = (L + R)/;
if(judge_DP(mid)) L = mid;
else R = mid;
}
return L;
} int main(int argc, char *argv[])
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
int T;
cin >> T;
while(T--){
cin >> n >> M;
for(int i = ;i <= n;i ++)
cin >> p[i].l >> p[i].v;
if(judge_no()){
puts("-1");
continue;
}
if(judge_oo()){
puts("oo");
continue;
}
sort(p+,p+n+,cmp);
p[].l = - , p[].v = ;
int L = , R = p[n].l;
cout << solve(L,R) << endl;
}
return ;
}

B

解法:模拟。字符串模拟

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int i,j;
int n,m;
int num_1,num_2;
int t;
int sum,ans,flag;
string s_1,s_2,s_3;
string sss;
string ss[10000];
string c;
map<string,int>q1;
map<string,int>q2;
int main()
{
cin>>t;
while(t--)
{
cin>>n>>c;
num_1=0;
for(i=0; i<n; i++)
{
cin>>sss;
ans=sss.find(".");
s_1=sss.substr(0,ans);
s_2=sss.substr(ans+1,sss.length());
if(s_2==c)
{
int ans_2=sss.find("(");
int ans_3=sss.find(")");
if((ans_2!=-1&&ans_2<ans_3))
{
// num_1++;
ss[num_1++]=sss.substr(0,ans_2);
// cout<<sss.substr(0,ans_2)<<endl;
}
else if(ans_2==-1||ans_3==-1)
{
// num_1++;
ss[num_1++]=sss.substr(0,ans);
// cout<<sss.substr(0,ans)<<endl;
}
}
}
for(i=0; i<num_1; i++)
{
// cout<<ss[i]<<"A"<<endl;
}
// cout<<num_1<<endl;
for(i=0; i<num_1; i++)
{
q1[ss[i]]++;
}
for(i=0; i<num_1; i++)
{
if(q2[ss[i]]==0)
{
q2[ss[i]]=1;
if(q1[ss[i]]==1)
{
cout<<ss[i]<<"."<<c<<endl;
}
else
{
cout<<ss[i]<<"."<<c<<" "<<q1[ss[i]]<<endl;
}
}
}
q1.clear();
q2.clear();
}
return 0;
}

C

解法:树状数组寻找逆序对+预处理

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath> using namespace std; const int M = ; long long ans[M + ];
int G[M + ],c[M + ]; int Lowbit(int x)
{
return x & (-x);
} void Insert(int x,int d)
{
while(x<=M){
c[x]+=d;
x+=Lowbit(x);
}
} int Sum(int x)
{
int sum=;
while(x>){
sum+=c[x];
x-=Lowbit(x);
}
return sum;
} void init()
{
memset(G,-,sizeof G);
memset(ans,,sizeof ans);
memset(c,,sizeof c);
G[] = ;
for(int i = ; i <= ;i++){
if(G[i] == -){
for(int j = i;j <= ;j += i){
if(G[j] == -){
G[j] = i;
}
}
}
}
for(int i=;i<=;i++)
{
Insert(G[i],);
ans[i] = ans[i-] + (i-Sum(G[i]));
}
} int main()
{
init();
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
cout<<ans[n]<<endl;
}
return ;
}

D

解法:模版题,最小覆盖圆

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const double eps=1e-;
struct Point{
double x,y;
}p[];
double dis(const Point &a,const Point &b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
Point circumcenter(const Point &a,const Point &b,const Point &c)
{ //返回三角形的外心
Point ret;
double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/;
double a2=c.x-a.x,b2=c.y-a.y,c2=(a2*a2+b2*b2)/;
double d=a1*b2-a2*b1;
ret.x=a.x+(c1*b2-c2*b1)/d;
ret.y=a.y+(a1*c2-a2*c1)/d;
return ret;
}
void min_cover_circle(Point *p,int n,Point &c,double &r){ //c为圆心,r为半径
random_shuffle(p,p+n); //
c=p[]; r=;
for(int i=;i<n;i++)
{
if(dis(p[i],c)>r+eps) //第一个点
{
c=p[i]; r=;
for(int j=;j<i;j++)
if(dis(p[j],c)>r+eps) //第二个点
{
c.x=(p[i].x+p[j].x)/;
c.y=(p[i].y+p[j].y)/;
r=dis(p[j],c);
for(int k=;k<j;k++)
if(dis(p[k],c)>r+eps) //第三个点
{//求外接圆圆心,三点必不共线
c=circumcenter(p[i],p[j],p[k]);
r=dis(p[i],c);
}
}
}
}
}
int main(){
int n;
Point c;
double r;
int t;
cin>>t;
while(t--)
{
cin>>n;
for(int i=; i<n; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
min_cover_circle(p,n,c,r);
printf("%.1f %.1f\n",c.x,c.y);
} return ;
}

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

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

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

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

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

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

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

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

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

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

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

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

    JankTao相亲记 解法:排序 #include<stdio.h> #include<string.h> #include<iostream> #include& ...

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

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

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

    Beautiful Palindrome Number 题意:求N里面有多少个符合要求的数字(数字要求:回文数,且前一半部分是不严格递增) 解法:打表 #include<bits/stdc++. ...

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

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

随机推荐

  1. centos6 搭建ELK

    mark一下时间:2016年2月19日10:17:09 记录使用 Logstash: Logstash服务的组件,用于处理传入的日志. Elasticsearch: 存储所有日志 Kibana 4: ...

  2. rename 快速移动文件或者文件夹

    有几种情况: 1.对于文件,rename可以在不同盘符之间移动. 2.对于空文件夹,rename也可以在不同盘符之间移动.但是目标文件夹的父目录必须存在. 3.对于非空文件夹,只能在同一盘符下移动. ...

  3. iOS Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:7962

      Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Cac ...

  4. 使用putty组件向服务器上传或下载文件

    基于SSH的连接 上传文件: pscp -P 28661(portNum) -pw password sourceFilePath user@serverIP:destinationFilePath ...

  5. IOS第七天(6:UiTableView编辑模式, 拖动位置 ,滑动删除)

    **********UiTableView编辑模式, 拖动位置 ,滑动删除 #import "HMViewController.h" @interface HMViewContro ...

  6. Apache Spark源码走读之24 -- Sort-based Shuffle的设计与实现

    欢迎转载,转载请注明出处. 概要 Spark 1.1中对spark core的一个重大改进就是引入了sort-based shuffle处理机制,本文就该处理机制的实现进行初步的分析. Sort-ba ...

  7. python 安装mysql-python模块

    方式一 使用yum安装 # yum install MySQL-python 方式二 使用pip 安装 # pip install mysql-python 使用pip方式安装需要提前安装如下依赖 m ...

  8. 如何把自己打造成技术圈的papi酱

    最近半年,一个叫papi酱的平胸女子连续在微博.朋友圈.创业圈刷屏,当之无愧成了中文互联网的第一大网红.呃,你以为我会巴拉巴拉说一堆网工创业的事?NO,今天想借papi酱的话题跟大家一起聊聊程序员如何 ...

  9. html5 canvas围绕中心点旋转

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. Oracle 小案例

    create database cstd; use cstd; /*1:建立学生表*/ create table student ( 学号 ) primary key, 姓名 ), 性别 ), 年龄 ...