20140323组队赛 2012福建省第三届ACM省赛题目
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-03-17)
Description
You are given two positive integers A and B in Base C. For the equation:
A=k*B+d
We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.
For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:
(1) A=0*B+123
(2) A=1*B+23
As we want to maximize k, we finally get one solution: (1, 23)
The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.
Output
Sample Input
3
2bc 33f 16
123 100 10
1 1 2
Sample Output
(0,700)
(1,23)
(1,0)
分析:给两个整数A、B(C进制),根据公式A=k*B+d;求k,d>=0时k最大时的一组解。如果A<B,那么答案是(0,A)。如果A>=B,那么答案是((int)A/B,A%B)。
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std; __int64 get_num(char *s,int c)
{
int i,n=strlen(s)-;
__int64 num=;
for(i=n;i>=;i--)
{
if(''<=s[i] && s[i]<='') num+=(int)pow(c*1.0,(n-i)*1.0)*(s[i]-'');
else num+=(int)pow(c*1.0,(n-i)*1.0)*(s[i]-'a'+);
}
return num;
} int main()
{
int T,C;
__int64 A,B;
char s1[],s2[];
scanf("%d",&T);
while(T--)
{
scanf("%s %s %d",s1,s2,&C);
A=get_num(s1,C);
B=get_num(s2,C);
if(A<B)
{
printf("(0,%I64d)\n",A);
}
else printf("(%I64d,%I64d)\n",A/B,A%B);
}
return ;
}
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2014-03-02)
Description
Bin has a dream that he and Jing are both in a wonderland full of beautiful gifts. Bin wants to choose some gifts for Jing to get in her good graces.
There are N different gifts in the wonderland, with ID from 1 to N, and all kinds of these gifts have infinite duplicates. Each time, Bin shouts loudly, “I love Jing”, and then the wonderland random drop a gift in front of Bin. The dropping probability for gift i (1≤i≤N) is P(i). Of cause, P(1)+P(2)+…+P(N)=1. Bin finds that the gifts with the higher ID are better. Bin shouts k times and selects r best gifts finally.
That is, firstly Bin gets k gifts, then sorts all these gifts according to their ID, and picks up the largest r gifts at last. Now, if given the final list of the r largest gifts, can you help Bin find out the probability of the list?
Input
The first line of the input contains an integer T (T≤2,000), indicating number of test cases.
For each test cast, the first line contains 3 integers N, k and r (1≤N≤20, 1≤k≤52, 1≤r≤min(k,25)) as the description above. In the second line, there are N positive float numbers indicates the probability of each gift. There are at most 3 digits after the decimal point. The third line has r integers ranging from 1 to N indicates the finally list of the r best gifts’ ID.
Output
Sample Input
4
2 3 3
0.3 0.7
1 1 1
2 3 3
0.3 0.7
1 1 2
2 3 3
0.3 0.7
1 2 2
2 3 3
0.3 0.7
2 2 2
Sample Output
0.027000
0.189000
0.441000
0.343000
题目大意:有N种礼物,每喊一次掉下一个礼物,每个礼物掉下来的概率为pi,呼喊k次,只选取r个编号较大的礼物。
分析:根据排列组合来计算概率,设编号ai有ni个,由于k可能大于r,根据乘法原理它概率分两部分:
第一部分:r个中最小编号(minn)外的概率Power(p[i],m[i])*C(m[i],r)*Power(p[i+1],m[i+1])*C(m[i+1],r-m[i])....;
第二部分:k-r个礼物,有多种情况(最小编号的个数(0,k-r))。可以把小于最小编号的看成一个种礼物(p=sum{pi,i<minn}),根据加法原理计算。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std; int N,K,R;
double p[]; inline int min(int a,int b){ return a<b?a:b;} double Power(double a,int b)
{
double ret=;
while(b)
{
if(b&) ret=ret*a;
a=a*a;
b>>=;
}
return ret;
} __int64 C(int k,int n)
{
int i;
__int64 ans=;
for ( i = ; i <=k ; i++)
{
ans*= (n-i+);
ans/=i;
}
return ans;
} int main()
{
int T,i,temp,Min,kk,rt;
double Minp,ans,tp;
map<int,int> m;
scanf("%d",&T);
while(T--)
{
m.clear();
Min=;Minp=;ans=1.0;
scanf("%d %d %d",&N,&K,&R);
kk=K;
for(i=;i<=N;i++) scanf("%lf",p+i);
for(i=;i<=R;i++){ scanf("%d",&temp);m[temp]++;Min=min(Min,temp);}
for(i=;i<Min;i++) Minp+=p[i];
for(i=Min+;i<=N;i++)
{
if(m[i]>)
{
ans*=Power(p[i],m[i])*C(m[i],kk);
kk=kk-m[i];
}
}
tp=;
for(i=;i<=K-R; i++)
{
rt=K-R-i;
tp+=((Power(p[Min],m[Min]+i)*C(m[Min]+i,K-R+m[Min])) * Power(Minp,rt));
}
ans*=tp;
printf("%.6lf\n",ans);
}
return ;
}
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2012-12-11)
Description
In this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.
You are given 3 positive integers n, L and R. Print the result of f(n,L)+f(n,L+1)+...+f(n,R), please.
Input
The first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000, L≤R).
Output
Sample Input
3
1 2 3
100 2 100
100 3 100
Sample Output
0
382
332
#include<stdio.h> int main()
{
int n,l,r,t;
int sum;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&l,&r);
sum = ;
for(int i =l;i<=r;i++)
{
sum +=(int)(n/i*1.0);
}
printf("%d\n",sum);
}
return ;
}
Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
System Crawler (2012-12-11)
Description
Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations:
Operation 1: AND opn L R
Here opn, L and R are integers.
For L≤i≤R, we do A[i]=A[i] AND opn (here "AND" is bitwise operation).
Operation 2: OR opn L R
Here opn, L and R are integers.
For L≤i≤R, we do A[i]=A[i] OR opn (here "OR" is bitwise operation).
Operation 3: XOR opn L R
Here opn, L and R are integers.
For L≤i≤R, we do A[i]=A[i] XOR opn (here "XOR" is bitwise operation).
Operation 4: SUM L R
We want to know the result of A[L]+A[L+1]+...+A[R].
Now can you solve this easy problem?
Input
The first line of the input contains an integer T, indicating the number of test cases. (T≤100)
Then T cases, for any case, the first line has two integers n and m (1≤n≤1,000,000, 1≤m≤100,000), indicating the number of elements in A and the number of operations.
Then one line follows n integers A[0], A[1], ..., A[n-1] (0≤A[i]<16,0≤i<n).
Then m lines, each line must be one of the 4 operations above. (0≤opn≤15)
Output
Sample Input
1
4 4
1 2 4 7
SUM 0 2
XOR 5 0 0
OR 6 0 3
SUM 0 2
Sample Output
7
18
Hint
A = [1 2 4 7]
SUM 0 2, result=1+2+4=7;
XOR 5 0 0, A=[4 2 4 7];
OR 6 0 3, A=[6 6 6 7];
SUM 0 2, result=6+6+6=18.
//;Write by lk1993, 2014.3.23
#include <stdio.h>
#include <string.h> const int M = + ; int sum[M]; inline void pushDown(int rt)
{
if(sum[rt] >= )
{
sum[rt << ] = sum[rt << | ] = sum[rt];
sum[rt] = -;
}
} inline void pushUp(int rt)
{
if(sum[rt << ] != - && sum[rt << | ] != - && sum[rt << ] == sum[rt << | ])
{
sum[rt] = sum[rt << ];
}
} void build(int l, int r, int rt)
{
if(l == r)
{
scanf("%d", &sum[rt]);
return ;
}
int m = (l + r) >> ;
build(l, m, rt << );
build(m + , r, rt << | );
pushUp(rt);
} void update(char op, int val, int ul, int ur, int l, int r, int rt)
{
if(ul <= l && ur >= r)
{
if(sum[rt] >= )
{
if('A' == op) sum[rt] &= val;
else if('X' == op) sum[rt] ^= val;
else if('O' == op) sum[rt] |= val;
return ;
}
}
pushDown(rt);
int m = (l + r) >> ;
if(ul <= m)
{
update(op, val, ul, ur, l, m, rt << );
}
if(ur > m)
{
update(op, val, ul, ur, m + , r, rt << | );
}
pushUp(rt);
} int query(int ql, int qr, int l, int r, int rt)
{
if(ql <= l && qr >= r)
{
if(sum[rt] >= )
{
return sum[rt] * (r - l + );
}
}
pushDown(rt);
int m = (l + r) >> ;
int ret = ;
if(ql <= m)
{
ret += query(ql, qr, l, m, rt << );
}
if(qr > m)
{
ret += query(ql, qr, m + , r, rt << | );
}
return ret;
} int main(int argc, char* argv[])
{
#ifdef __MYLOCAL
freopen("in.txt", "r", stdin);
#endif int t, n, m, a, b, c;
char oper[]; scanf("%d", &t);
while(t--)
{
scanf("%d%d", &n, &m);
memset(sum, -, sizeof(sum));
build(, n, );
while(m--)
{
scanf("%s", oper);
if('S' == oper[])
{
scanf("%d%d", &a, &b);
printf("%d\n", query(a + , b + , , n, ));
}
else
{
scanf("%d%d%d", &a, &b, &c);
update(oper[], a, b + , c + , , n, );
}
}
} return ;
}
System Crawler (2012-12-11)
Description
Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one 1*2 grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is empty.
There is only one Cao Cao. The number of Cross general, vertical general, and soldier is not fixed. How many ways can all the people stand?
Input
There is a single integer T (T≤4) in the first line of the test data indicating that there are T test cases.
Then for each case, only one integer N (1≤N≤4) in a single line indicates the length of Hua Rong Dao.
Output
Sample Input
2
1
2
Sample Output
0
18
Hint
#include<iostream>
#include<cstdio>
using namespace std; bool vis[][];
int N,ans; void dfs(int i,int j)
{
if(j>)
{
i++;j=;
if(i>N)
{
ans++;return ;
}
}
if(vis[i][j]) dfs(i,j+);
if(!vis[i][j])
{
vis[i][j]=true;dfs(i,j+);vis[i][j]=false;
}
if(!vis[i][j] && j+<= && !vis[i][j+])
{
vis[i][j]=vis[i][j+]=true;
dfs(i,j+);
vis[i][j]=vis[i][j+]=false;
}
if(!vis[i][j] && i+<=N && !vis[i+][j])
{
vis[i][j]=vis[i+][j]=true;
dfs(i,j+);
vis[i][j]=vis[i+][j]=false;
}
return ;
}
int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
ans=;
for(i=;i<N;i++)
{
for(j=;j<;j++)
{
memset(vis,false,sizeof(vis));
vis[i][j]=vis[i][j+]=vis[i+][j]=vis[i+][j+]=true;
dfs(,);
}
}
printf("%d\n",ans);
}
return ;
}
System Crawler (2013-10-19)
Description
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
For each test case:
The first line contains one integer n (1≤n≤100), the number of stars.
The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.
Output
Sample Input
1
3
0 0
10 0
5 1000
Sample Output
1
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; typedef __int64 LL ;
struct Point {
LL x, y;
Point(LL x=, LL y=):x(x),y(y) { }
}p[]; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (const Vector& A, double p) { return Vector(A.x*p, A.y*p); }
double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; }
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }
double Length(const Vector& A) { return sqrt(Dot(A, A)); } Point read_point()
{
Point a;
scanf("%I64d %I64d",&a.x,&a.y);
return a;
} bool is_ok(int i,int j,int k)
{
bool flag=;
if(-Dot(p[j]-p[i],p[k]-p[i])>0.0000001) flag=;
if(-Dot(p[j]-p[k],p[i]-p[k])>0.0000001) flag=;
if(-Dot(p[i]-p[j],p[k]-p[j])>0.0000001) flag=;
return flag;
}
int main()
{
int T,i,n,j,k,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<n;i++) p[i]=read_point();
ans=;
for(i=;i<n;i++)
{
for(j=i+;j<n;j++)
{
for(k=j+;k<n;k++)
{
if(is_ok(i,j,k))
ans++;
}
}
}
printf("%d\n",ans);
}
return ;
}
System Crawler (2013-05-11)
Description
Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| means the length of n’s 10-base notation. Then we can swap n[i] and n[j].
For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.
Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?
Please note that in this problem, leading zero is not allowed!
Input
The first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.
Output
Sample Input
3
9012 0
9012 1
9012 2
Sample Output
9012
1092
1029
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; int len,findex;
char s[]; struct node
{
char ch;
int x;
}t; void find_min1()
{
t.ch='';t.x=len;
for(int j=len-;j>findex;j--)
{
if(s[j]<s[findex] && s[j]<=t.ch)
{
t.ch=s[j];
t.x=j;
}
}
} void find_min2()
{
t.ch='';t.x=len;
for(int j=len-;j>findex;j--)
{
if(s[j]<s[findex] && s[j]<=t.ch && s[j]>'')
{
t.ch=s[j];
t.x=j;
}
}
} void Swap(int i,int j)
{
char ch=s[i];
s[i]=s[j];s[j]=ch;
} int main()
{
int T,n,i;
scanf("%d",&T);
while(T--)
{
scanf("%s %d",s,&n);
len=strlen(s);
findex=;
for(i=;i<n;)
{
if(findex==len-) break;
find_min1();
if(findex== && t.ch=='') find_min2();
if(t.x==len)
{
findex++;
continue;
}
else
{
Swap(findex,t.x);
findex++;i++;
}
}
printf("%s\n",s);
}
return ;
}
20140323组队赛 2012福建省第三届ACM省赛题目的更多相关文章
- [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !
n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Lim ...
- Sdut 2409 The Best Seat in ACM Contest(山东省第三届ACM省赛 H 题)(模拟)
题目描述 Cainiao is a university student who loves ACM contest very much. It is a festival for him once ...
- [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number
Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...
- 山东省第三届ACM省赛
Solved ID PID Title Accepted Submit A 2407 Impasse (+) 0 0 B 2415 Chess 0 0 C 2414 An interest ...
- Sdut 2416 Fruit Ninja II(山东省第三届ACM省赛 J 题)(解析几何)
Time Limit: 5000MS Memory limit: 65536K 题目描述 Haveyou ever played a popular game named "Fruit Ni ...
- sdut2408 pick apples (贪心+背包)山东省第三届ACM省赛
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/svitter/article/details/24642587 本文出自:http://blog.c ...
- 2012-2014 三年浙江 acm 省赛 题目 分类
The 9th Zhejiang Provincial Collegiate Programming Contest A Taxi Fare 25.57% (166/649) (水 ...
- [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛
本文出自:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&am ...
- [2012山东ACM省赛] Pick apples (贪心,完全背包,枚举)
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描述 Once ago, there is a mystery yard which on ...
随机推荐
- OC和C++的区别
C++语言特点: 1.在C语言的基础上进行扩充和完善,使C++兼容了C语言的面向过程特点,又成为了一种面向对象的程序设计语言: 2.可以使用抽象数据类型进行基于对象的编程: 3.可以使用多继承.多态进 ...
- UIViewController 的 edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets属性
1.有时你命名设置了某控件的y坐标为0,确总是被导航栏遮挡住,如下: UILabel *label = [[UILabel alloc] init]; label.text = @"请 ...
- 【转】VS2010下MFC的串口编程
串口通信简介 一般来说,计算机都有一个或多个串行端口,这些串口提供了外部设备与PC进行数据传输和通信的通道,在CPU和外设之间充当解释器的角色.当字符数据从CPU发送给外设时,这些字符数据将被转换成串 ...
- pandas的数据联级
一.索引的堆(stack) 1.行列的转化: Stack():列转行 Unstack():行转列 Stack对应行, 使用小技巧:使用stack()的时候,level等于哪一个,哪一个就消失,出现在行 ...
- JS - encodeURI与encodeURIComponent的区别
encodeURI(String)主要用于整个URI(例如,http://www.jxbh.cn/illegal value.htm),而encodeURIComponent(String)主要用于对 ...
- 02等待单个线程返回WaitForSingleObject
windows 多线程之等待线程返回 多线程编程中,有时我们需要等待某一线程完成了特定的操作之后再继续做其他事情,要实现这个目的,可以使用 Windows API 函数 WaitForSingle ...
- RSA非对称加密算法实现过程
RSA非对称加密算法实现过程 非对称加密算法有很多,RSA算法就是其中比较出名的算法之一,下面是具体实现过程 <?php /** */ class Rsa { /** * private key ...
- APP客户端图片上传PHP接口
1.客户端 file_get_contents($_FILES['img']['tmp_name']) //获取临时目录下的上传文件流,加密传给接口 2.接口处理端 $img = file_get ...
- redis代理集群(Twemproxy)(1)
redis主从+哨兵模式只解决了读的分布式操作,大大提高了性能:但是写操作,只有主主机器才能进行,从机器无法进行写操作.此时,Twemproxy也就出现了. 这个模式单纯的安装有些复杂,需要引入很多的 ...
- type和object
一.定义 1.object是所有新式类的父类 2.type是所有类的类 二.解析 下面通过代码来比较一下object和type的关系(__class__获取所属的类,__bases__获取父 ...