8-13-Exercise
昨天的比赛好郁闷.......倒不是因为题目......在快要比赛的时候突然所有的网站都进不去了.......改了半天的DNS & IP......比赛都比了1个多小时才进去.....都不想做题了= =|||
A.POJ 3210 Coins
这道题感觉似曾相识......貌似很久以前做过= =
其实仔细想一下,题目并不难~若n为偶数的话,那么"偶正+偶负"翻转的一定是偶数次;而"奇正+奇负"翻转的一定是奇数次~故没有确定的最少次数~
但是,若n为奇数的话,是"奇正+偶负"或"偶正+奇负",翻转的都是偶数次~故存在确定的最少次数!
代码:
#include <iostream>
#include <cstdio>
using namespace std; int main()
{
int n;
while(scanf("%d",&n),n)
{
if(n%==)
printf("No Solution!\n");
else
printf("%d\n",n-);
}
return ;
}
//memory:164KB time:16ms
B.HDU 4506 小明系列故事――师兄帮帮忙
此处求k^t时要采用反复平方法(快速幂)【该方法在另一篇博客里讲的有~链接】,否则会TLE~
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; #define M 1000000007
int T,i;
__int64 a[],b[];
__int64 n,t,k; __int64 Pow(__int64 x,__int64 n) //快速幂~
{
__int64 ret=,s=x;
while()
{
if(n&)
ret=(ret%M*s%M)%M;
if(n>>=)
s=(s%M*s%M)%M;
else
break;
}
return ret;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%I64d%I64d%I64d",&n,&t,&k);
k=Pow(k,t);
t=t%n; //因为t很有可能会大于n,故这一步很重要!!!!
for(i=;i<n;i++)
scanf("%I64d",&a[i]);
for(i=t;i<n;i++)
b[i]=(a[i-t]%M*k)%M;
for(i=;i<t;i++)
b[i]=(a[i+n-t]%M*k)%M;
for(i=;i<n-;i++)
printf("%I64d ",b[i]);
printf("%I64d\n",b[n-]);
}
return ;
}
//memory:428KB time:46ms
C.HDU 2546 饭卡
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; int main()
{
int n,a[],f[],m;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
scanf("%d",&m);
if(m>=)
{
memset(f,,sizeof(f));
for(int i=;i<n-;i++)
for(int j=m-;j>=a[i];j--)
if(f[j-a[i]]+a[i]>f[j] && f[j-a[i]]+a[i]<=m-)
f[j]=f[j-a[i]]+a[i];
printf("%d\n",m-f[m-]-a[n-]);
}
else
printf("%d\n",m);
}
return ;
}
D.HDU 1026 Ignatius and the Princess I
......Loading......
8-13-Exercise的更多相关文章
- MIT 6.828 JOS学习笔记13 Exercise 1.10
Lab 1 Exercise 10 为了能够更好的了解在x86上的C程序调用过程的细节,我们首先找到在obj/kern/kern.asm中test_backtrace子程序的地址, 设置断点,并且探讨 ...
- 12/13 exercise
gcc -[cog] gcc pro1.o pro2.o //create a executable file x.out if unnamed
- [未完成]关于Eclipse4RCP书中内容总结
原文地址http://www.vogella.com/tutorials/EclipseRCP/article.html Table of Contents 1. Eclipse 4 1.1. Wha ...
- DTrace to Troubleshoot Java Native Memory Problems
How to Use DTrace to Troubleshoot Java Native Memory Problems on Oracle Solaris 11 Hands-On Labs of ...
- BEC listen and translation exercise 13
The old lady sits on a mobile chair every morning. He got a large fortune when his father died, but ...
- MIT 6.828 JOS学习笔记5. Exercise 1.3
Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...
- Stanford coursera Andrew Ng 机器学习课程编程作业(Exercise 1)
Exercise 1:Linear Regression---实现一个线性回归 在本次练习中,需要实现一个单变量的线性回归.假设有一组历史数据<城市人口,开店利润>,现需要预测在哪个城市中 ...
- C# Development 13 Things Every C# Developer Should Know
https://dzone.com/refcardz/csharp C#Development 13 Things Every C# Developer Should Know Written by ...
- 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 ...
随机推荐
- Elasticsearch基础概念理解
熟悉ES中的几个关键概念: 节点(Node):一个elasticsearch运行的实例,其实就是一个java进程.一般情况下,一台机器运行在一台机器上. 集群(Cluster): 好几个有相同集群名称 ...
- Windows获取其他进程中Edit控件的内容
最近做的MFC项目中,有个获取其他进程中Edit控件内容的需求,本来以为是个很简单的问题,但是来来回回折腾了不少时间,发博记录一下. 刚开始拿到这个问题,很自然的就想到GetDlgItemText() ...
- 优化函数式编程:向 PHP 移植 Clojure 函数
许多通用程序设计语言试图兼容大多数编程范式,PHP 就属于其中之一.不论你想要成熟的面向对象的程序设计,还是程序式或函数式编程,PHP 都可以做到.但我们不禁要问,PHP 擅长函数式编程吗?本文系国内 ...
- Tomcat 6 支持 NIO -- Tomcat的四种基于HTTP协议的Connector性能比较(转载)
Tomcat从5.5版本开始,支持以下四种Connector的配置分别为: <Connector port="8081" protocol="org.apache. ...
- *[topcoder]LittleElephantAndIntervalsDiv1
http://community.topcoder.com/stat?c=problem_statement&pm=12822&rd=15707 第一次用C++提交,艰辛.首先想到可以 ...
- 基于FFmpeg和Qt的播放器 QtAV库
http://blog.csdn.net/ibingow/article/details/8144795
- delphi xe3的helper语法 good
在C#中有一个很有用的helper保留字,它可以让我们对已有的类添加额外功能,当时就在想delphi有这个保留字就好了,这样许多控件就不需要继承重写了.后来delphi 果然有了这个语法,到delph ...
- Sublime Text修改显示图标
选择喜欢的图片 首先你需要选择一个中意的图片做为新的图标,格式可以是png,jpg,gif的 转为ico格式 我们需要ico格式的图片,所以需要将上述的图片转换一下格式.同样,转ico格式的软件很多, ...
- URAL1244. Gentlemen(背包)
链接 以前做的题 VJ太水了 数组里面的数可能会小于0 当时没判断 #include <iostream> #include<cstdio> #include<cstri ...
- QNX环境
QNX开发环境和QNX虚拟机都搭建好了,开始写第一个QNX程序. 关于QNX程序开发的最好参考是QNX官网上的pdf书<10 Steps to Developing a QNX Program: ...