8-14-Exercise
这次是我这组出题......我出的是B、C、D【虽然本来是想出的很难......╮(╯▽╰)╭但是,没找到AC1000+同时又让我想出的难题......SO...我出的真的不难= =】,荆红出的是A,从此不再出的是D......
A.HDU 1789 Doing Homework again
用贪心做~先按分数从大到小排,若分数相同则按天数从大到小排。排好后,从头开始扫描,扫到未标记的点,就进行标记(A),同时看A点后是否还有要在A点的天数之内一定要完成的作业,直到把A点的天数填完,若天数不够填,则证明哪一门作业无法按时完成~
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; class Node
{
public:
int x,y;
}a[]; bool comp(Node w,Node q)
{
if(w.x==q.x)
return w.y>q.y;
return w.x>q.x;
} int main()
{
int t,number,b[],i,j,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(a,,sizeof(a));
for(i=;i<n;i++)
scanf("%d",&a[i].y);
for(i=;i<n;i++)
scanf("%d",&a[i].x);
sort(a,a+n,comp);
number=;
memset(b,,sizeof(b));
for(i=;i<n;i++)
{
for(j=a[i].y;j>;j--)
if(b[j]==)
{
b[j]=;
break;
}
if(j==)
number+=a[i].x;
}
printf("%d\n",number);
}
return ;
}
B.HDU 1846 Brave Game && C.HDU 1527 取石子游戏
这两道单独写的有:链接╮(╯▽╰)╭
D.POJ 1844 Sum
一道小清新的趣味数学题~【很有趣吧╮(╯▽╰)╭】
sum=1+2+3+4+...+i
当sum==s时,直接输出i;
当上一步无法做到时,则当第一次达到(sum-s)%2==0时,输出i即可~
证明【第二步,即此时sum达不到s,且sum>s】:
res=sum-s;
其实仔细想一想~很容易知道当改变sum里的+号时,sum永远是减去一个偶数【why?比如把sum中j前的加号改为减号,就是相当于sum-j-j,会减去2*j】~
SO~若res为奇数,无论如何改变sum中的加号,res永远都无法为0;只有res为偶数时,才有机会通过改变sum中的加号为0。因此当sum无法恰好达到s时,那么第一次达到res%2==0的i就是所求值~~~
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int main()
{
int s,sum,i,res;
while(~scanf("%d",&s))
{
sum=;
res=;
for(i=;;i++)
{
sum+=i;
res=sum-s;
if(sum==s) break;
if(res> && res%==)
break;
}
printf("%d\n",i);
}
return ;
}
//memory:164KB time:0ms
E.HDU 1142 A Walk Through the Forest
dijkstra+记忆化搜索
代码:
#include<iostream>
#include<cstdio>
#include<string.h>
#define N 1010
#define INF 2000000000 using namespace std; int map[N][N],lowcost[N],visited[N],d[N],p[N]; void dijkstra(int s,int n)
{
memset(visited,false,sizeof(visited));
int i,j,k,min;
for(i=;i<=n;i++)
{
lowcost[i]=map[s][i];
}
d[s]=;
visited[s]=true;
for(i=;i<n;i++)
{
min=INF;
for(j=;j<=n;j++)
{
if(!visited[j]&&min>lowcost[j])
{
min=lowcost[j];
k=j;
}
}
d[k]=min;
visited[k]=true;
for(j=;j<=n;j++)
{
if(!visited[j]&&lowcost[j]>map[k][j]+d[k])
lowcost[j]=map[k][j]+d[k];
}
}
} int DFS(int s,int n)
{
if(p[s]) return p[s];
if(s==) return ;
int i,sum=;
for(i=;i<=n;i++)
{
if(map[s][i]<INF&&d[s]>d[i])
{
if(p[i]) sum=sum+p[i];
else sum=sum+DFS(i,n);
}
}
sum=sum+p[s];
p[s]=sum;
return p[s];
} int main()
{
int i,j,n,m,u,v,w;
while(cin>>n&&n)
{
cin>>m;
memset(p,,sizeof(p));
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
map[i][j]=(i==j?:INF);
}
}
for(i=;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
map[u][v]=map[v][u]=w;
}
dijkstra(,n);
cout<<DFS(,n)<<endl;
}
return ;
}
//memory:4276KB time:78ms
8-14-Exercise的更多相关文章
- [未完成]关于Eclipse4RCP书中内容总结
原文地址http://www.vogella.com/tutorials/EclipseRCP/article.html Table of Contents 1. Eclipse 4 1.1. Wha ...
- 【Bell-Ford 算法】CLRS Exercise 24.1-4,24.1-6
本文是一篇笔记,大部分内容取自 CLRS 第三版,第 24.1 节. Exercise 24.1-4 Modify the Bellman-Ford algorithm so that it sets ...
- (14)Why some people find exercise harder than others
https://www.ted.com/talks/emily_balcetis_why_some_people_find_exercise_harder_than_others/transcript ...
- C - The C Answer (2nd Edition) - Exercise 1-4
/* Write a program to print the corresponding Celsius to Fahrenheit table. */ #include <stdio.h&g ...
- MIT 6.828 JOS学习笔记5. Exercise 1.3
Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...
- 《how to design programs》14章 再论自引用数据
这是一个家族谱: ;child(define-struct child (father mother name date eyes)) #lang racket ;child (define-stru ...
- CMSC 216 Exercise #5
CMSC 216 Exercise #5 Spring 2019Shell Jr (”Shellito”) Due: Tue Apr 23, 2019, 11:30PM1 ObjectivesTo p ...
- 软件测试:3.Exercise Section 2.3
软件测试:3.Exercise Section 2.3 /************************************************************ * Finds an ...
- 《学习OpenCV3》第14章课后习题
1.在一条含有 N 个点的封闭轮廓中,我们可以通过比较每个点与其它点的距离,找出最外层的点.(这个翻译有问题,而且这个问题是实际问题) a.这样一个算法的复杂度是多少? b.怎样用更快的速度完成这个任 ...
- 18 A GIF decoder: an exercise in Go interfaces 一个GIF解码器:go语言接口训练
A GIF decoder: an exercise in Go interfaces 一个GIF解码器:go语言接口训练 25 May 2011 Introduction At the Googl ...
随机推荐
- 关于 js 2个数组取差集怎么取
关于 js 2个数组取差集怎么取? 例如求var arr1 = [1]; var arr2 = [1,2];的差集方法一: Array.prototype.diff = function(a) { r ...
- 机器学习算法与Python实践之(二)支持向量机(SVM)初级
机器学习算法与Python实践之(二)支持向量机(SVM)初级 机器学习算法与Python实践之(二)支持向量机(SVM)初级 zouxy09@qq.com http://blog.csdn.net/ ...
- zepto源码学习-04 event
之前说完$(XXX),然后还有很多零零碎碎的东西需要去分析,结果一看代码,发现zepto的实现都相对简单,没有太多可分析的.直接略过了一些实现,直接研究Event模块,相比JQuery的事件系统,ze ...
- 移动js
http://blog.sina.com.cn/s/blog_6553196001015672.html http://blog.sina.com.cn/s/blog_6553196001014vjb ...
- 如何使用 Java8 实现观察者模式?(上)
[编者按]本文作者是 BAE 系统公司的软件工程师 Justin Albano.在本篇文章中,作者通过在 Java8 环境下实现观察者模式的实例,进一步介绍了什么是观察者模式.专业化及其命名规则,供大 ...
- activiti集成spring异常(DbSqlSession)
在eclipse配置一个简单的activiti项目,配置的是mysql数据库,报错如下: SLF4J: Failed to load class "org.slf4j.impl.Static ...
- Python sh库学习 上篇
官方文档有句话"allows you to call any program",并且:helps you write shell scripts in Python by givi ...
- 【HDOJ】2054 A == B ?
这道题目起初看,so easy.再看一下ac率,注意到没有说明变量类型.显然是一道字符串的题.需要考虑+/-符号位,+.1.-.1.00010.0.+0.-00.00等情况,同时数组开到100000以 ...
- Linux复制指定目录下的文件夹结构
[root@ebs12vis ~]# su - applmgr[applmgr@ebs12vis ~]$ cd $APPL_TOP/inv[applmgr@ebs12vis inv]$ find . ...
- CSS属性一览
CSS 属性 CSS 属性组: 动画 背景 边框和轮廓 盒(框) 颜色 内容分页媒体 定位 可伸缩框 字体 生成内容 网格 超链接 行框 列表 外边距 Marquee 多列 内边距 分页媒体 定位 打 ...