http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3844

第一个,n个数,每次操作最大数和最小数都变成他们的差值,最后n个数相同时输出此时的值,暴力跑。

 #include<cstdio>
int main(){
int t,n,a[];
while(~scanf("%d",&t)){
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
while(true){
int bid=,sid=;
for(int i=;i<n;i++){
if(a[bid]<a[i]) bid=i;
if(a[sid]>a[i]) sid=i;
}
if(a[bid]==a[sid]){
printf("%d\n",a[sid]);
break;
}
a[bid]=a[sid]=a[bid]-a[sid];
}
}
}
return ;
}

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5440

第二个,n个数,每次操作可以任意选两个数把他们变成他们gcd的值。最后问几步能都变成1,且输出每步选的数的下标。方法:先求出n个数的gcd,如果不为1,输出-1.否则一定能变成全1.变的方法是,先用第一个依次和后面的操作,直至第一个数变成1,然后再用第一个数把剩下的非1的都变掉。

 #include<cstdio>
#include<vector>
using namespace std;
const int M=1e5+;
typedef pair<int,int> pii;
int a[M];
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
vector<pii> ans;
int main(){
int n;
int cas=;
while(~scanf("%d",&n)){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
int now=a[];
for(int i=;i<=n;i++){
now=gcd(now,a[i]);
}
printf("Case %d: ",cas++);
if(now>){
puts("-1");
puts("");
continue;
}
ans.clear();
for(int i=;i<=n;i++){
int now=gcd(a[],a[i]);
a[]=a[i]=now;
ans.push_back(make_pair(,i));
if(now==) break;
}
for(int i=;i<=n;i++){
if(a[i]==) continue;
ans.push_back(make_pair(,i));
}
int len=ans.size();
printf("%d\n",len);
for(int i=;i<len;i++){
printf("%d %d\n",ans[i].first,ans[i].second);
}
puts("");
}
return ;
}

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5435

第三个,52张牌,没有大小王的,输入几张,那么剩下的就是我们可以使用的,必须全用上,问有几种排列使得字典序小于他输入的。

 #include<cstdio>
#include<cstring>
#define mt(a,b) memset(a,b,sizeof(a))
const int M=;
typedef long long LL;
const LL mod=1e9+;
char a[M];
int num[M];
int sheng[M];
int getval(char c){
if(c=='A') return ;
if(c=='J') return ;
if(c=='Q') return ;
if(c=='K') return ;
return c-'';
}
int s[M];
LL jc[M];
LL INV[M];
void inv_init() { //初始化%mod的乘法逆元
INV[]=;
for(int i=; i<M; i++) {
INV[i]=INV[mod%i]*(mod-mod/i)%mod;
}
}
int main(){
inv_init();
jc[]=;
for(int i=;i<M;i++){
jc[i]=jc[i-]*i%mod;
}
while(~scanf("%s",a)){
int la=strlen(a);
mt(num,);
int val;
int ls=;
for(int i=;i<la;i++){
if(a[i]==''){
val=;
i++;
}
else{
val=getval(a[i]);
}
num[val]++;
s[ls++]=val;
}
for(int i=;i<=;i++){
sheng[i]=-num[i];
}
LL ans=;
for(int i=;i<ls;i++){
for(int j=;j<s[i];j++){
if(sheng[j]==) continue;
LL tmp=jc[-ls-i-];
for(int k=;k<=;k++){
if(sheng[k]==) continue;
if(k==j){
for(int u=;u<=sheng[k]-;u++){
tmp*=INV[u];
tmp%=mod;
}
}
else{
for(int u=;u<=sheng[k];u++){
tmp*=INV[u];
tmp%=mod;
}
}
}
ans+=tmp;
ans%=mod;
}
if(sheng[s[i]]){
sheng[s[i]]--;
int sum=;
for(int j=;j<=;j++){
sum+=sheng[j];
}
if(sum==){
if(i<ls-) ans++;
break;
}
continue;
}
break;
}
printf("%lld\n",ans%mod);
}
return ;
}

end

matrix_2015_1 138 - ZOJ Monthly, January 2015的更多相关文章

  1. 思维+multiset ZOJ Monthly, July 2015 - H Twelves Monkeys

    题目传送门 /* 题意:n个时刻点,m次时光穿梭,告诉的起点和终点,q次询问,每次询问t时刻t之前有多少时刻点是可以通过两种不同的路径到达 思维:对于当前p时间,从现在到未来穿越到过去的是有效的值,排 ...

  2. ZOJ Monthly, January 2018 训练部分解题报告

    A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...

  3. ZOJ 3913 Bob wants to pour water ZOJ Monthly, October 2015 - H

    Bob wants to pour water Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge There i ...

  4. ZOJ 3911 Prime Query ZOJ Monthly, October 2015 - I

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  5. ZOJ 3910 Market ZOJ Monthly, October 2015 - H

    Market Time Limit: 2 Seconds      Memory Limit: 65536 KB There's a fruit market in Byteland. The sal ...

  6. ZOJ 3908 Number Game ZOJ Monthly, October 2015 - F

    Number Game Time Limit: 2 Seconds      Memory Limit: 65536 KB The bored Bob is playing a number game ...

  7. ZOJ 3905 Cake ZOJ Monthly, October 2015 - C

    Cake Time Limit: 4 Seconds      Memory Limit: 65536 KB Alice and Bob like eating cake very much. One ...

  8. ZOJ 3903 Ant ZOJ Monthly, October 2015 - A

    Ant Time Limit: 1 Second      Memory Limit: 32768 KB There is an ant named Alice. Alice likes going ...

  9. ZOJ Monthly, July 2015

    B http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5552 输入n,表示有n个数1到n.A先拿,B后拿,依次拿,每次可以拿任意一 ...

随机推荐

  1. tomcat学习笔记1

    tomcat是一个开源软件,是由java语言编写的,它工作的话需要运行在jvm虚拟机中,说到jvm不得不说下java这个大名鼎鼎的编程 语言了 java这个编程语言最优秀的特点要数write once ...

  2. Mysql导入导出 改密命令总结(笔记三)

    一.从数据库导出数据 注意这些语句的执行是在在没进入mysql命令行之前,在mysql命令行不行 C:\Windows\system32>导出命令 而不是 Mysql>导出命令 1.导出整 ...

  3. 一款jQuery实现重力弹动模拟效果特效,弹弹弹,弹走IE6

    一款jQuery实现重力弹动模拟效果特效 鼠标经过两块黑色div中间的红色线时,下方的黑快会突然掉落, 并在掉落地上那一刻出现了弹跳的jquery特效效果,非常不错,还兼容所有的浏览器, 适用浏览器: ...

  4. C++列出完数

    题目内容:自然数中,完数寥若晨星,请在从1到某个整数范围中打印出所有的完数来.所谓“完数”是指一个数恰好等于它的所有不同因子之和.例如,6是完数,因为6=1+2+3.而24不是完数,因为24≠1+2+ ...

  5. PHP中英文字符串截取函数无乱码(mb_substr)和获取中英文字符串字数函数(mb_strlen)

    mb_substr( $str, $start, $length, $encoding ) $str,需要截断的字符串 $start,截断开始处,起始处为0 $length,要截取的字数 $encod ...

  6. Ztack学习笔记(6)-广播组播点播

    Zigbee网络中进行数据通信主要有三种类型:单播.组播.广播.那这三种方式如何设置呢,在哪里设置呢, 一. 广播 当应用程序需要将数据包发送给网络的每一个设备时,使用这种模式.广播的短地址有三种 0 ...

  7. EOF 与 getchar()

    1.EOF EOF是end of file的缩写,表示"文字流"(stream)的结尾.这里的"文字流",可以是文件(file),也可以是标准输入(stdin) ...

  8. Ubuntu下部署java JDK和eclipse IDE

    安装Java编程开发环境: Ubuntu默认安装openjava,可以通过java -version查看是否安装.但我使用Ubuntu9.10升级到10.04LTS时,openjava没有了.另外,如 ...

  9. 关于table元素的认识

    表格是网页上最常见的元素,但是,现在对很多刚入行的前端们那是谈table色变.那是为啥?这是表格的框架的简单.明了.在传统的网页中使用没有边框的表格来排版是非常流行.在web标准逐渐深入设计领域以后, ...

  10. echo换行的蛋疼事

    openstack@openstack:~$ echo "abc" | shasum03cfd743661f07975fa2f1220c5194cbaff48451  -而使用Ja ...