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. Mybatis bug修正

    http://1358440610-qq-com.iteye.com/blog/1827391

  2. CF192div2-C - Purification

    题意: 从给定的图中找出某些点,这些点能够消除同一行和同一列的“怪物”.求使得最少的点的位置. 关键:要想消除整张的图的妖怪,必须选中n个点(对于n行n列来说)!!!!!!!!!!! 做法:对于每一行 ...

  3. Uva 12361 File Retrieval 后缀数组+并查集

    题意:有F个单词,1 <= F <=60 , 长度<=10^4, 每次可以输入一个字符串,所有包含该字串的单词会形成一个集合. 问最多能形成多少个不同的集合.集合不能为空. 分析:用 ...

  4. USB 枚举过程详解

    Windows 对USB设备的枚举过程流程图如图1所示: 图1 WP8的USB功能只支持一个配置,三个接口,也就是分别有如下的字段: 设备描述符的bNumConfigurations=1, 配置描述符 ...

  5. Postman(API & HTTP请求调试插件)和Apizza fiddler

    http://blog.csdn.net/u011012932/article/details/51456263#comments

  6. 捉虫记:SHGetSpecialFolderPath返回错误码为2

    通常我们想获得系统的一些路径时,都会使用一些Shell函数.比如SHGetSpecialFolderPath,SHGetFolderPath,SHGetKnownFolderPath等,传入我们想要的 ...

  7. C#反射实例应用--------获取程序集信息和通过类名创建类实例

    AppDomain.CurrentDomain.GetAssemblies();获取程序集,但是获取的只是已经加载的dll,引用的获取不到. System.Reflection.Assembly.Ge ...

  8. Android开发之PackageManager类

    PackageManger,可以获取到手机上所有的App,并可以获取到每个App中清单文件的所有内容. 设置应用程序版本号在应用程序的manifest文件中定义应用程序版本信息.2个必须同时定义的属性 ...

  9. a++与=++a的区别

    //a++;//a=a+1;              // ++a;//a=a+1;               //Console.WriteLine(a++);// Console.WriteL ...

  10. 从头开始编写一个Orchard网上商店模块(4) - 创建ProductPart

    原文地址:http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-par ...