玲珑杯”ACM比赛 Round #5


1056 - A plus B

Two octal number integers a, b are given, and you need calculate the result a - b in octal notation.
If the result is negative, you should use the negative sign instead of complement notation.

INPUT
The first line is an integer T(1 <= T <= 1000), indicating the number of test cases.For each case, the first and only line contains two octal integers a, b.(0 <= a, b < 2^32)
OUTPUT
Print the result, one per line, in octal notation.
SAMPLE INPUT
176 7
SAMPLE OUTPUT
67

题意:给你两个八进制的数a,b  去a-b的值,也是八进制

解题思路:水题,直接模拟一下就好,八进制先转换成十进制 运算在转回去,  注意负数,0, 这几种情况

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll c[1111];
ll work1(ll t)
{
	ll ans=0,temp=1;
	ll num=t;
	while(num) {
		ans+=num%10*temp;
		temp*=8;
		num/=10;
	}
	return ans;
}

int work2(ll t)
{
	ll num=t;
	int k=0;
	while(num) {
		c[++k]=num%8;
		num/=8;
	}
	return k;
}

int main()
{
	int k,T,i,j,flag;
	ll a,b,num;
	cin>>T;
	while(T--) {
		cin>>a>>b;
		if(a>=b) flag=1;
		else flag=-1;
		num=work1(a)-work1(b);
		if(num==0) {
			cout<<"0"<<endl;
			continue;
		}
		k=work2(num*flag);
		if(flag==-1) cout<<"-";
		for(i=k;i>=1;i--) cout<<c[i];
		cout<<endl;
	}
	return 0;
} 



DESCRIPTION

The "private value" is the value that occurs, but most infrequent.

An array of integers is given, and you need print the private values of the array.

Please notice that, there might be several private values, and you need print them in increasing order.

INPUT
The first line is an integer T(1 <= T <= 4), indicating the number of test cases.For each case, the first line contains an integer n (n <= 100000).The second line contains n integers a_i (0 <= a_i <= 10^9),
OUTPUT
For each case, print all private values in increasing order in a line.
SAMPLE INPUT
271 1 2 2 3 3 355 3 2 4 1
SAMPLE OUTPUT
1 21 2 3 4 5


求出现最小次数的数字,如果存在多组,字典序输出

思路:先排序,在最后一位出现的数字标上该数字出现的个数,然后维护一个最小值,在线性扫一遍输出即可, 此题是吴神的想法,orz

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int N = 1e5+100;
int a[N],b[N];
int main()
{
	int num,T,i,j,n,flag,first;
	scanf("%d",&T);
	while(T--) {
		first=1;
		scanf("%d",&n);
		for(i=0;i<n;i++) {
			scanf("%d",&a[i]);
			b[i]=0;
		}
		sort(a,a+n);
		num=1;flag=N;
		for(i=1;i<n;i++) {
			if(a[i]!=a[i-1]) {
				b[i-1]=num;
				flag=min(flag,num);
				num=1;
			}
			else num++;
		}
		b[n-1]=num;
		flag=min(flag,num);
		for(i=0;i<n;i++) {
			if(b[i]==flag) {
				if(first) printf("%d",a[i]);
				else printf(" %d",a[i]);
				first=0;
			}
		}
		printf("\n");
	}
	return 0;
}


DESCRIPTION

Coco just learned a math operation call mod.Now,there is an integer a

and n integers b1,,bn. After selecting some numbers from b1,,bn in any order, say c1,,cr, Coco want to make sure that amodc1modc2modmodcr=0\ (i.e., a will become the remainder divided by ci each time, and at the end, Coco want a to become 0). Please determine the minimum value of r. If the goal cannot be achieved, print 1

instead.

INPUT
The first line contains one integer T(T5)
, which represents the number of testcases. For each testcase, there are two lines:1. The first line contains two integers n and a\ ( 1n20,1a106).2. The second line contains n integers b1,,bn\ ( 1in,1bi106
).
OUTPUT
Print T
answers in T
lines.
SAMPLE INPUT
22 92 72 96 7
SAMPLE OUTPUT
2-1


题意:给你一组数,问用最少用多少个数字可以先x 取余后为0,不能的话输出-1

思路:由于该组数只有20个,可以大暴力,O(2^20) 。。 先降序排列,因为小的在前,mod之后后面的数字都不起作用。


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int inf = 0x3f3f3f3f;
int a[22],n;
int ans;
void dfs(int num,int id,int cnt)
{
	if(num==0) {
		ans=min(ans,cnt);
		return ;
	}
	if(id>=n) return ;
	if(a[id+1]<=num) dfs(num%a[id+1],id+1,cnt+1);
	dfs(num,id+1,cnt);
	return ;
}
int main()
{
	int num,i,j,T;
	scanf("%d",&T);
	while(T--) {
		scanf("%d%d",&n,&num);
		for(i=1;i<=n;i++) scanf("%d",&a[i]);
		sort(a+1,a+1+n,greater<int>());
		ans=inf;
		dfs(num,0,0);
		if(ans==inf) printf("-1\n");
		else printf("%d\n",ans);
	}
	return 0;
}



DESCRIPTION

An array with length n is given.
You should support 2 types of operations.

1 x y change the x-th element to y.
2 l r print the variance of the elements with indices l, l + 1, ... , r.
As the result may not be an integer, you need print the result after multiplying (r-l+1)^2.

The index of the array is from 1.

INPUT
The first line is two integer n, m(1 <= n, m <= 2^{16}), indicating the length of the array and the number of operations.The second line is n integers, indicating the array. The elements of the array 0<=ai<=104
.The following m lines are the operations. It must be either1 x yor2 l r
OUTPUT
For each query, print the result.
SAMPLE INPUT
4 41 2 3 42 1 41 2 42 1 42 2 4
SAMPLE OUTPUT
20242


题意:给你一段序列,有两只操作,1 先x位置的数字变成y  2 查询l到r 区间的方差。

思路:将方差换简后,你会发现只要维护两格东西就行了,一个是x的区间和,一个是x*x的区间和。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 70000;
typedef long long ll;
ll bit[N],a[N],bit2[N];
int n;

ll sum(int i) 
{
	ll s=0;
	while(i>0) {
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}

ll sum2(int i) 
{
	ll s=0;
	while(i>0) {
		s+=bit2[i];
		i-=i&-i;
	}
	return s;
}

void add(int i,int x)
{
	while(i<=n) {
		bit[i]+=x;
		i+=i&-i;
	}
}

void add2(int i,int x)
{
	while(i<=n) {
		bit2[i]+=x;
		i+=i&-i;
	}
}


int main()
{
	ll m,i,j,x,y,op,num,ans,t;
	while(scanf("%lld%lld",&n,&m)!=EOF) {
	
	for(i=1;i<=n;i++) {
		scanf("%lld",&x);
		
		a[i]=x;
		add(i,x);
		add2(i,x*x);
	}
	while(m--) 
	{
		scanf("%lld%lld%lld",&op,&x,&y);
		
		if(op==1) 
		{
			num=y-a[x];
			add(x,num);
			num=y*y-a[x]*a[x];
			add2(x,num);
			a[x]=y;
		}
		else {
			if(x>1) ans=-(sum(y)-sum(x-1))*(sum(y)-sum(x-1))+(y-x+1)*(sum2(y)-sum2(x-1));
			else ans=-sum(y)*sum(y)+y*(sum2(y));
			printf("%lld\n",ans);
		}
	}
	}
	return 0;
}

P=NP?

INPUT
First line contains a single integer T which denotes the number of test cases. For each test case, there is two numbers which denote N and P separated by a space.(0<=N< 231
,0<=P< 231
)The input data is no large than 1M.
OUTPUT
For each case, output the "Y" or "N" in a single line.
SAMPLE INPUT
21 123123 0
SAMPLE OUTPUT
YY


题意:给你T组数字,输入n,p  问是否存在n*p=p

思路: 想简单了,输入的数字可能是小数,所以这题就比较恶心,你要大模拟,判断该数字。。。

输出yes只有两种情况,要么n=1,要么p=0

n可能是 000000001.0000000

p可能是 0000.000000000000


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
int main()
{
	int  T,i,j,count,flag,dec;
	string n,p;
	cin>>T;
	while(T--) {
		flag=1;
		cin>>n>>p;
		for(i=0;i<p.length()&&flag;i++) {
			if(p[i]!='0'&&p[i]!='.') flag=0; 
		}
		if(flag) cout<<"Y"<<endl;
		else {
			flag=1;count=0;dec=0;
			for(i=0;i<n.length();i++) {
				if(n[i]=='1') count++;
				if(n[i]=='.') dec=1;
			}
			if(count!=1) cout<<"N"<<endl;
			else {
				for(i=0;i<n.length();i++) {
					if(n[i]=='1') break;
				}
				if(dec && n[i+1]!='.') flag=0;
				if(dec==0 && i!=n.length()-1) flag=0;
				if(flag) cout<<'Y'<<endl;
				else cout<<"N"<<endl;  
			} 
		}
	}
	return 0;
} 





  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值