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 ...
随机推荐
- C++函数转换成C#函数
/// /// </param> /// <returns></returns> ...
- jquery怎么实现左右滑动的问题
var len = $("#b span").length, curindex = 0; $("#leftRun").click(function(){ if( ...
- portal、portlet、portlet容器三个概念
什么是portal Portlet规范中是这样定义portal的: A portal is a web based application that –commonly- provides perso ...
- oracle----删除数据
1. 删除数据:delete语句: 语法: DELETE FROM table_name; (1),无条件删除: SQL> create table testdel as select * fr ...
- oracle学习之-----操作表中的数据
1. 向表中添加数据(Insert 语句): 添加的语法: INSERT INTO table_name(column1,column2,column3,......) VALUES(value1,v ...
- Yahoo! Logo ASCII Animation in 462 bytes of C
Last week I put together another obfuscated C program and have been urged by my coworkers to post it ...
- apt-get用法
转自apt-get语法- - 对于debian来说,安装软件大多都是通过apt-get来实现的. 1.apt-get update 更新软件包信息库.在Debian中,软件包是通过一个数据库来管理的, ...
- ANDROID_MARS学习笔记_S01原始版_019_SERVICE之Transact
一.代码1.xml(1)activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/ ...
- git workflow 原文 以及缺点
原文链接 http://nvie.com/posts/a-successful-git-branching-model/ 有人发现git work flow的缺点,历史提交会变得混乱 http://e ...
- MyBatis学习总结1
MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以使用简单的XML或注解用 ...