# 玲珑杯”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.

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

#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

#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

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
lines.
SAMPLE INPUT
22 92 72 96 7
SAMPLE OUTPUT
2-1

#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

#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;
}

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

{
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;
}
while(m--)
{
scanf("%lld%lld%lld",&op,&x,&y);

if(op==1)
{
num=y-a[x];
num=y*y-a[x]*a[x];
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

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;
}