8-14-小练

这次是我这组出题......我出的是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的更多相关文章

  1. [未完成]关于Eclipse4RCP书中内容总结

    原文地址http://www.vogella.com/tutorials/EclipseRCP/article.html Table of Contents 1. Eclipse 4 1.1. Wha ...

  2. 【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 ...

  3. (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 ...

  4. C - The C Answer (2nd Edition) - Exercise 1-4

    /* Write a program to print the corresponding Celsius to Fahrenheit table. */ #include <stdio.h&g ...

  5. MIT 6.828 JOS学习笔记5. Exercise 1.3

    Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...

  6. 《how to design programs》14章 再论自引用数据

    这是一个家族谱: ;child(define-struct child (father mother name date eyes)) #lang racket ;child (define-stru ...

  7. CMSC 216 Exercise #5

    CMSC 216 Exercise #5 Spring 2019Shell Jr (”Shellito”) Due: Tue Apr 23, 2019, 11:30PM1 ObjectivesTo p ...

  8. 软件测试:3.Exercise Section 2.3

    软件测试:3.Exercise Section 2.3 /************************************************************ * Finds an ...

  9. 《学习OpenCV3》第14章课后习题

    1.在一条含有 N 个点的封闭轮廓中,我们可以通过比较每个点与其它点的距离,找出最外层的点.(这个翻译有问题,而且这个问题是实际问题) a.这样一个算法的复杂度是多少? b.怎样用更快的速度完成这个任 ...

  10. 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 ...

随机推荐

  1. Python创建list

    Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可以用一个list表示: >>> ['Mic ...

  2. asp.net中对象的序列化,方便网络传输

    对象序列化 是将对象状态转换为可保持或传输的格式的过程.反序列化 是将流转换为对象序列化和反序列化相结合 可以使对象数据轻松的存储和传递 在 .NET 中,如果是对象可序列化,需要在 声明对象的开始部 ...

  3. apt-get命令讲解

    apt-get是一条linux命令,适用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库中搜索.安装.升级.卸载软件或操作系统. apt-get是debian,ubuntu发行版的包管理工具 ...

  4. memcached源代码包下载

    先下载libevent https://github.com/downloads/libevent/libevent/libevent-2.0.18-stable.tar.gz 再下载memcache ...

  5. SDUT 1570 C 旅行(DFS)

    点我看题目 题意 : 中文不详述. 思路 :就是DFS一下,只要到达终点条数就加1,然后再注意一下方向,因为我就是没注意方向WA了,只能向上向右走,x是行,所以向上是x-1,向右是y+1,因为我没弄好 ...

  6. PHP unlink() 函数

    定义和用法 unlink() 函数删除文件. 若成功,则返回 true,失败则返回 false. 语法 unlink(filename,context) 参数 描述 filename 必需.规定要删除 ...

  7. linux 和 ecos 内核线程创建/信号量/event等对比

    ecos: int gx_thread_create (const char *thread_name, gx_thread_id *thread_id, void(*entry_func)(void ...

  8. Qt中QString,int,char,QByteArray之间相互转换

    http://blog.csdn.net/ymc0329/article/details/7284514 int  转 QString int m=1; QString b; b=QString::n ...

  9. Android 如何在Java代码中手动设置控件的marginleft

    1.定义LayoutParams LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.La ...

  10. QQ输入法个人设置

    常用 按键 外观 词库 账户 高级