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. Linux安装配置php环境的方法

    本文实例讲述了Linux安装配置php环境的方法.分享给大家供大家参考,具体如下: 1.获取安装文件: http://www.php.net/downloads.php php-5.3.8.tar.g ...

  2. Hive中的排序语法

    ORDER BY hive中的ORDER BY语句和关系数据库中的sql语法相似.他会对查询结果做全局排序,这意味着所有的数据会传送到一个Reduce任务上,这样会导致在大数量的情况下,花费大量时间. ...

  3. ThinkPHP之中利用commom被继承控制器控制访问每一个控制器方法都需要验证是否已经登录!

    防止 <?php namespace Home\Controller; use Think\Controller; class CommonController extends Controll ...

  4. ThinkPHP实现联动菜单;

    联动菜单,首先给你看看前端是怎么写的:

  5. find your present

    Description In the present, and their card numbers are , , , , .so your present will be the one with ...

  6. oracle 查看隐含参数脚本

    set linesize 132 column name format a30 column value format a25 select x.ksppinm name, y.ksppstvl va ...

  7. Ubuntu下sqlite3的安装及使用

    Sqlite是一款轻型的数据库,实现了多数SQL-92标准,包括事务(原子性,一致性,隔离性和持久性 ACID),触发器与多数复杂查询.对于一个移动手持设备的应用开发者,Sqlite是居家旅行必备数据 ...

  8. hdu 2102 A计划

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2102 A计划 Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸 ...

  9. 2天驾驭DIV+CSS (技巧篇)(转)

     这是去年看到的一片文章,感觉在我的学习中,有不少的影响.于是把它分享给想很快了解css的兄弟们.本文是技巧篇. 基础篇[知识一] “DIV+CSS” 的叫法是不准确的[知识二] “DIV+CSS” ...

  10. SQL Server Analysis Services 数据挖掘

    假如你有一个购物类的网站,那么你如何给你的客户来推荐产品呢?这个功能在很多 电商类网站都有,那么,通过SQL Server Analysis Services的数据挖掘功能,你也可以轻松的来构建类似的 ...