HDU - 6023  //编译错误不算罚时

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int vis[100];
int num[20];
int main()
{int t;cin>>t;while(t--){int n,m;cin>>n>>m;int id,h1,f1;char str[5];int cnt=0,sum=0;memset(vis,0,sizeof(vis));memset(num,0,sizeof(num));for(int i=0;i<m;i++){scanf("%d",&id);scanf("%d",&h1);getchar();scanf("%d",&f1);scanf("%s",str);id=id-1000;if(vis[id]==1)continue;if(strcmp(str,"AC")==0){vis[id]=1;sum+=h1*60+f1+num[id];}elsenum[id]+=20;}for(int i=0;i<=n;i++)if(vis[i]==1)cnt++;cout<<cnt<<" "<<sum<<endl;}return 0;
}

HDU - 6024

HDU’s nn classrooms are on a line ,which can be considered as a number line. Each classroom has a coordinate. Now Little Q wants to build several candy shops in these nn classrooms.

The total cost consists of two parts. Building a candy shop at classroom ii would have some cost cici. For every classroom PP without any candy shop, then the distance between PP and the rightmost classroom with a candy shop on PP's left side would be included in the cost too. Obviously, if there is a classroom without any candy shop, there must be a candy shop on its left side.

Now Little Q wants to know how to build the candy shops with the minimal cost. Please write a program to help him.

InputThe input contains several test cases, no more than 10 test cases. 
In each test case, the first line contains an integer  n(1≤n≤3000)n(1≤n≤3000), denoting the number of the classrooms. 
In the following  nn lines, each line contains two integers  xi,ci(−109≤xi,ci≤109)xi,ci(−109≤xi,ci≤109), denoting the coordinate of the  ii-th classroom and the cost of building a candy shop in it. 
There are no two classrooms having same coordinate.OutputFor each test case, print a single line containing an integer, denoting the minimal cost.Sample Input

3
1 2
2 3
3 4
4
1 7
3 1
5 10
6 1

Sample Output

5
11

题意是,花费的代价是:要是在这个位置上建立糖果屋就花菲建糖果屋的代价,要不就在这个位置上建糖果屋花费的代价就是,这个屋子的坐标减去离他最近的建糖果屋的坐标,还有最左面的屋子一定要建立糖果屋的。

不是贪心的题:

举个反例:

当输入     5

1 2

2 2

3 2

4 3

5 4

的时候,在2这个做标处,按照贪心处理的话不会在这个坐标建糖果屋,花费是: 2+1+2+3+4, 而选择建的话是 2+2+1+2+3+4,所以贪心的思想是错误的。

点击打开题解链接

#include<iostream>
#include<algorithm>
#include<cstring>
#include <cstdio>
//#include <bits/stdc++.h>
#define INF  0x3f3f3f3f
#define LL long long
//#define IO ios::sync_with_stdio(false);
using namespace std;
LL dp[3005][2];
struct node
{LL id;LL cost;}s[3005];
bool cmp(node a,node b)
{return a.id<b.id;
}
int main()
{int n;while(scanf("%d",&n)!=EOF)//不加EOF TLE!{for(int i=0;i<n;++i){//cin>>s[i].id>>s[i].cost;scanf("%lld%lld",&s[i].id,&s[i].cost);}sort(s,s+n,cmp);memset(dp,INF,sizeof(dp));dp[0][1]=s[0].cost;for(int i=1;i<n;++i){dp[i][1]=min(dp[i-1][0],dp[i-1][1])+s[i].cost;LL ans=0;for(int j=i-1;j>=0;--j){ans+=(s[j+1].id-s[j].id)*(i-j);dp[i][0]=min(dp[j][1]+ans,dp[i][0]);}}printf("%lld\n",min(dp[n-1][1],dp[n-1][0]));// cout<<min(dp[n-1][0],dp[n-1][1])<<endl;}return 0;
}
#include<iostream>
#include<algorithm>
#include <cstdio>
//#include <bits/stdc++.h>
#include <cstring>
#define INF  0x3f3f3f3f //用1e20就不对
//#define IO ios::sync_with_stdio(false);
using namespace std;
long long dp[3005][2]={0};
long long dis[3005][3005];
struct node
{int id;int cost;bool operator <(const node &b)const{return id<b.id;}
}s[3005];
int main()
{int n;while(scanf("%d",&n)!=EOF){for(int i=1;i<=n;++i){scanf("%d%d",&s[i].id,&s[i].cost);}sort(s+1,s+n+1);memset(dis,0,sizeof(dis));memset(dp,INF,sizeof(dp));for(int i=1;i<=n;++i){for(int j=1;j<i;++j)if(i!=j)dis[j][i]=dis[j][i-1]+s[i].id-s[j].id;//(1+i-j)*(i-j)*0.5;}// for(int i=1;i<=n;++i)//  {//     for(int j=i+1;j<=n;++j)//      dis[i][j]=dis[i][j-1]+s[j].id-s[i].id;//(1+i-j)*(i-j)*0.5;// }dp[1][1]=s[1].cost;for(int i=2;i<=n;++i){dp[i][1]=min(dp[i-1][0],dp[i-1][1])+s[i].cost;for(int j=i-1;j;--j){dp[i][0]=min(dp[i][0],dp[j][1]+dis[j][i]);}}long long MIN=min(dp[n][0],dp[n][1]);printf("%I64d\n",MIN);}return 0;
}

HDU - 6025 :

Do you know what is called ``Coprime Sequence''? That is a sequence consists of nnpositive integers, and the GCD (Greatest Common Divisor) of them is equal to 1. 
``Coprime Sequence'' is easy to find because of its restriction. But we can try to maximize the GCD of these integers by removing exactly one integer. Now given a sequence, please maximize the GCD of its elements.

InputThe first line of the input contains an integer  T(1≤T≤10)T(1≤T≤10), denoting the number of test cases. 
In each test case, there is an integer  n(3≤n≤100000)n(3≤n≤100000) in the first line, denoting the number of integers in the sequence. 
Then the following line consists of  nn integers  a1,a2,...,an(1≤ai≤109)a1,a2,...,an(1≤ai≤109), denoting the elements in the sequence.OutputFor each test case, print a single line containing a single integer, denoting the maximum GCD.Sample Input

3
3
1 1 1
5
2 2 2 3 2
4
1 2 4 8

Sample Output

1
2
2

用公约数的前缀和和后缀方法:

总结:求一串数字的最大公约数和数字的顺序无关,

//#include<iostream>
//#include<algorithm>
//#include <cstdio>
#include <bits/stdc++.h>
using namespace std;//long long dp[3005][3005]={0};
int num[100005];
int pre[100005];
int nre[100005];
int _gcd(int a,int b)
{return b?_gcd(b,a%b):a;
}
int main()
{int Case,n;cin>>Case;for(int t=0;t<Case;++t){scanf("%d",&n);for(int i=0;i<n;++i)scanf("%d",&num[i]);pre[0]=num[0];nre[n-1]=num[n-1];for(int i=1;i<n;++i){pre[i]=_gcd(pre[i-1],num[i]);}for(int i=n-2;i>=0;--i){nre[i]=_gcd(nre[i+1],num[i]);}int MAX=max(pre[n-2],nre[1]);for(int i=1;i<n-1;++i){MAX=max(MAX,_gcd(pre[i-1],nre[i+1]));}printf("%d\n",MAX);}return 0;
}

用的一种找规律的方法,这道题就让去掉一个数字然后求他们的最大公约数,那么你不管怎么去(偏大的还是偏小的)那个数字,剩下的数字的最大公约数肯定是小于这个数字串的最小的那个数字,可以从数字串a的a1位置开始暴力,(要是去掉2个数字,可以从a2位置的数字开始枚举,不过去除的数字太多的话,应该会TLE,所以不如上面的求前缀后缀的方法好)

#include<iostream>
#include<algorithm>
using namespace std;int main()
{int t;cin>>t;int n;int a[100005];while(t--){cin>>n;for(int i=0;i<n;i++){cin>>a[i];}sort(a,a+n);int h=a[1];int flag=0;for(int j=h;j>=1;j--){int sum=0;for(int i=0;i<n;i++){if(a[i]%j==0)sum++;if(sum>=n-1){flag=1;cout<<j<<endl;break;}}if(flag==1)break;}}return 0;
}

(队友提到一道题,给你n个数字求他们的最大公因子是多少:从他们的最小的那个数字n开始找到1要是中间的有个数字%==0这个数字串的次数为数字串的个数,就是这个串的最大公约数)

HDU - 6027

You are encountered with a traditional problem concerning the sums of powers. 
Given two integers nn and kk. Let f(i)=ikf(i)=ik, please evaluate the sum f(1)+f(2)+...+f(n)f(1)+f(2)+...+f(n). The problem is simple as it looks, apart from the value of nnin this question is quite large. 
Can you figure the answer out? Since the answer may be too large, please output the answer modulo 109+7109+7.

InputThe first line of the input contains an integer  T(1≤T≤20)T(1≤T≤20), denoting the number of test cases. 
Each of the following  TT lines contains two integers  n(1≤n≤10000)n(1≤n≤10000) and  k(0≤k≤5)k(0≤k≤5). 
OutputFor each test case, print a single line containing an integer modulo  109+7109+7.Sample Input

3
2 5
4 2
4 1

Sample Output

33
30
10

大数,

import java.util.*;
import java.math.*;
public class Main{
public static void main(String args[]) {  Scanner cin=new Scanner (System.in);int n;n=cin.nextInt();//BigInteger a;int a;int k;BigInteger MOD=new  BigInteger("1000000007");for(int i=0;i<n;++i){BigInteger sum=BigInteger.ZERO;a=cin.nextInt();k=cin.nextInt();BigInteger j=BigInteger.ONE;//=new BigInteger("1");for(int m=0;m<a;m++){//  System.out.println();sum=sum.add(j.pow(k));sum=sum.mod(MOD); j=j.add(BigInteger.ONE);}System.out.println(sum);}
}
}

用快速幂:

#include<iostream>
#include<algorithm>
#include <cstdio>
using namespace std;
const int MOD = 7+1e9;
//#define  MOD 1e9+7 越界了
long long  n,k;
long long POW(long long  p,long long x)
{long long ans=1;while(x){if(x&1)ans=(ans*p)%MOD;p=(p*p)%MOD;x>>=1;}return ans;
}
int main()
{long long  t;cin>>t;while(t--){long long sum=0;cin>>n>>k;for(long long  p=1;p<=n;++p){sum=(sum+POW(p,k))%MOD;}//printf("%lld\n",sum);cout<<sum<<endl;}return 0;
}

Graph Theory

HDU - 6029

Little Q loves playing with different kinds of graphs very much. One day he thought about an interesting category of graphs called ``Cool Graph'', which are generated in the following way: 
Let the set of vertices be {1, 2, 3, ..., nn}. You have to consider every vertice from left to right (i.e. from vertice 2 to nn). At vertice ii, you must make one of the following two decisions: 
(1) Add edges between this vertex and all the previous vertices (i.e. from vertex 1 to i−1i−1). 
(2) Not add any edge between this vertex and any of the previous vertices. 
In the mathematical discipline of graph theory, a matching in a graph is a set of edges without common vertices. A perfect matching is a matching that each vertice is covered by an edge in the set. 
Now Little Q is interested in checking whether a ''Cool Graph'' has perfect matching. Please write a program to help him. 

InputThe first line of the input contains an integer  T(1≤T≤50)T(1≤T≤50), denoting the number of test cases. 
In each test case, there is an integer  n(2≤n≤100000)n(2≤n≤100000) in the first line, denoting the number of vertices of the graph. 
The following line contains  n−1n−1 integers  a2,a3,...,an(1≤ai≤2)a2,a3,...,an(1≤ai≤2), denoting the decision on each vertice.OutputFor each test case, output a string in the first line. If the graph has perfect matching, output ''Yes'', otherwise output ''No''. 
Sample Input

3
2
1
2
2
4
1 1 2

Sample Output

Yes
No
No

意思是给你一个数n代表有n个顶点(1,2,3.....n),然后再给你n-1个数字代表对顶点2,3,4,,,,n所做的操作,操作有两种形式,1和2

1代表把当前顶点(ai)及其之前的顶点都加上一条边,可以放到一个集合里面(边往集合哩放的条件是,这个边的两个顶点在这个集合里面都没有出现过)2这个操作代表这个点是个孤立的顶点不给他加边,然后问到最后那个集合里面是不是包含这n个所有顶点。mmp

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int t;cin>>t;while(t--){int n,op;cin>>n;//  int edge[100005]={0};int mgj=0;//统计没加进去的点的个数for(int i=2;i<=n;++i){scanf("%d",&op);//cin>>op;if(op==1){if(!mgj)mgj=0;elsemgj--;}elsemgj++;}if(n&1)//奇数构成的边肯定要剩下一个顶点孤立printf("No\n");else if(!mgj)printf("Yes\n");// cout<<"Yes"<<endl;elseprintf("No\n");// cout<<"NO"<<endl;}return 0;
}
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int t;cin>>t;while(t--){int n,order;cin>>n;int flag=-1,sum=0;//sum统计加进去的个数for(int i=2;i<=n;i++){cin>>order;if(order==1){if(sum<i-1)sum+=2;}}if(n%2==1)printf("No\n");else{if(sum==n) printf("Yes\n");else printf("No\n");}}return 0;
}

2018 Spring Team Contest D HDU - 6023、HDU - 6024、HDU - 6025 、HDU - 6027 、HDU - 6029相关推荐

  1. 2018 Spring Team Contest B

    C:URAL - 2064 Young gardener didn't visit his garden for a long time, and now it's not very pleasant ...

  2. HDU 4738 Caocao‘s Bridges(桥、任何位运算一定都要加括号、因为有重边所以用前向星)

    HDU 4738 Caocao's Bridges(桥.任何位运算一定都要加括号.因为有重边所以用前向星) Caocao was defeated by Zhuge Liang and Zhou Yu ...

  3. 2018 Multi-University Training Contest 3 Problem F. Grab The Tree 【YY+BFS】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6324 Problem F. Grab The Tree Time Limit: 2000/1000 MS ...

  4. 2018 Multi-University Training Contest 4 Problem E. Matrix from Arrays 【打表+二维前缀和】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6336 Problem E. Matrix from Arrays Time Limit: 4000/20 ...

  5. 2018个人年度总结:我是如何从嵌入式开发到服务器开发对接天猫精灵、小爱智能音箱服务器!懵懂 | 奋斗 | 进阶 | 信心

    文章目录 一.个人总结? 二.步入职场那些事. 2.1 大学项目引起兴趣. 2.2 第一次面试. 二.职业发展的奠基石------ 机智云. 三.嵌入式开发.移动开发.服务器开发. 3.1.嵌入式开发 ...

  6. 如何使用Java+SSM(Spring+SpringMVC+Mybatis)开发个性化新闻推荐系统 在线新闻推荐系统 基于用户项目协同过滤、内容、聚类、关联规则推荐算法实现WebNewsRSMEx

    如何使用Java+SSM(Spring+SpringMVC+Mybatis)开发个性化新闻推荐系统 在线新闻推荐系统 基于用户项目协同过滤.内容.聚类.关联规则推荐算法实现WebNewsRSMEx 一 ...

  7. 基于spring boot的毕业设计论文选题申报管理系统设计与实现 毕业论文+项目源码、

    下载地址:https://download.csdn.net/download/ouyangxiaobai123/22679732 项目介绍: 基于spring boot的毕业设计论文选题申报管理系统 ...

  8. 《Spring源码深度解析 郝佳 第2版》bean的加载、循环依赖的解决

    往期博客: <Spring源码深度解析 郝佳 第2版>容器的基本实现与XML文件的加载 <Spring源码深度解析 郝佳 第2版>XML标签的解析 往期博客完成了xml文件加载 ...

  9. 如何使用Spring+SpringMVC+Mybatis开发实现个性化小说推荐系统 协同过滤推荐算法实现 基于用户、项目的协同过滤推荐 基于聚类、关联规则、内容推荐算法 WebNovelCFRS

    如何使用Spring+SpringMVC+Mybatis开发实现个性化小说推荐系统 协同过滤推荐算法实现 基于用户.项目的协同过滤推荐 基于聚类.关联规则.内容推荐算法 WebNovelCFRS 一. ...

最新文章

  1. idea怎么使用jacoco生成报告_Intellij IDEA解析jacoco结果文件的方法
  2. Python基础教学系列— 基础语法
  3. InfluxDB基本概念和操作
  4. IEEE Access latex 图片caption无法换行的问题
  5. 对计算机的理解大一1000,大一计算机实训报告总结范文-求计算机实习报告1000字左右,急急急?...
  6. PCA对特征点描述子降维
  7. 4 转推流格式_ppt 转 pdf怎么转?这个宝藏技巧不会太亏了!
  8. linux 环境安装及学习
  9. kotlin密封类_Kotlin密封级
  10. 阶乘浅析poj1150 3406 zoj1222 2358
  11. Selenium2学习笔记——自动化环境搭建
  12. 测评绿联蓝牙音频接收器
  13. springboot集成shiro
  14. python量化交易策略实例_Python写一个量化股票提醒系统实例
  15. 联想大数据“双拳”出击另有深意
  16. 基站定位经纬度查询免费api接口-LBS数据仓库
  17. java 如何给游戏加音效,修改添加游戏中各种音效的步骤
  18. 基本的html文档组成三要素是哪些,三大构成 复习资料
  19. 业务需求近期准备深度学习下SpringCloud为加深印象提高学习效果故做此笔记以备后面复习查看之用
  20. Vue之集成阿里云滑块验证

热门文章

  1. WIN7建立网络映射磁盘
  2. 使用Silverlight for Embedded开发绚丽的界面(3)
  3. patch是什么意思啊_学 Vue 看这个就够了 - 什么是 Vue.js
  4. 前沿 | 全球最具影响力开源数据库峰会开幕在即 阿里云精彩议题先睹为快
  5. AOP统一处理请求日志
  6. 如何用JavaScript手动实现一个栈
  7. 上海市国资大数据课题启动仪式暨数据资产技术及金融行业应用沙龙隆重开幕...
  8. Android下的数据存储与访问、权限
  9. 一分钟了解阿里云产品:对象存储OSS概述
  10. COCOA的UIVIEW动画护展