A. Ultra-Fast Mathematician
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.

One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.

In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.

Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞(length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.

Now you are going to take part in Shapur's contest. See if you are faster and more accurate.

Input

There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.

Output

Write one line — the corresponding answer. Do not omit the leading 0s.

Examples
input
1010100
0100101
output
1110001
input
000
111
output
111
input
1110
1010
output
0100
input
01110
01100
output
00010

思路:水,直接判断相等不相等;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-7
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=;
char a[N],b[N];
int main()
{
scanf("%s%s",a,b);
int x=strlen(a);
for(int i=;i<x;i++)
{
printf("%d",(a[i]!=b[i]?:));
}
return ;
}
B. Hard Work
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!

Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher gave them 3 strings and asked them to concatenate them. Concatenating strings means to put them in some arbitrary order one after the other. For example from concatenating Alireza and Amir we can get to AlirezaAmir or AmirAlireza depending on the order of concatenation.

Unfortunately enough, the teacher forgot to ask students to concatenate their strings in a pre-defined order so each student did it the way he/she liked.

Now the teacher knows that Shapur is such a fast-calculating genius boy and asks him to correct the students' papers.

Shapur is not good at doing such a time-taking task. He rather likes to finish up with it as soon as possible and take his time to solve 3-SAT in polynomial time. Moreover, the teacher has given some advice that Shapur has to follow. Here's what the teacher said:

  • As I expect you know, the strings I gave to my students (including you) contained only lowercase and uppercase Persian Mikhi-Script letters. These letters are too much like Latin letters, so to make your task much harder I converted all the initial strings and all of the students' answers to Latin.
  • As latin alphabet has much less characters than Mikhi-Script, I added three odd-looking characters to the answers, these include "-", ";" and "_". These characters are my own invention of course! And I call them Signs.
  • The length of all initial strings was less than or equal to 100 and the lengths of my students' answers are less than or equal to 600
  • My son, not all students are genius as you are. It is quite possible that they make minor mistakes changing case of some characters. For example they may write ALiReZaAmIR instead of AlirezaAmir. Don't be picky and ignore these mistakes.
  • Those signs which I previously talked to you about are not important. You can ignore them, since many students are in the mood for adding extra signs or forgetting about a sign. So something like Iran;;-- is the same as --;IRAN
  • You should indicate for any of my students if his answer was right or wrong. Do this by writing "WA" for Wrong answer or "ACC" for a correct answer.
  • I should remind you that none of the strings (initial strings or answers) are empty.
  • Finally, do these as soon as possible. You have less than 2 hours to complete this.
Input

The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively.

In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students.

Next n lines contain a student's answer each. It is guaranteed that the answer meets what the teacher said. Each answer iconsists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). Length is from 1 to 600, inclusively.

Output

For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.

Examples
input
Iran_
Persian;
W_o;n;d;e;r;f;u;l;
7
WonderfulPersianIran
wonderful_PersIAN_IRAN;;_
WONDERFUL___IRAN__PERSIAN__;;
Ira__Persiann__Wonderful
Wonder;;fulPersian___;I;r;a;n;
__________IranPersianWonderful__________
PersianIran_is_Wonderful
output
ACC
ACC
ACC
WA
ACC
ACC
WA
input
Shapur;;
is___
a_genius
3
Shapur__a_is___geniUs
is___shapur___a__Genius;
Shapur;;is;;a;;geni;;us;;
output
WA
ACC
ACC

题意:不区分大小写跟符号,问能否由三个字符串拼接成,可以输出ACC,否则WA;

思路:字符串模拟;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-7
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=;
string a[];
char str[][N];
map<string,int>ans;
int main()
{
for(int i=;i<;i++)
scanf("%s",&str[i]);
for(int i=;i<;i++)
{
int len=strlen(str[i]);
for(int j=;j<len;j++)
{
if(str[i][j]>='a'&&str[i][j]<='z')
a[i]+=str[i][j];
if(str[i][j]>='A'&&str[i][j]<='Z')
a[i]+=str[i][j]-'A'+'a';
}
}
ans[a[]]=;
ans[a[]]=;
ans[a[]]=;
ans[a[]+a[]]=;
ans[a[]+a[]]=;
ans[a[]+a[]]=;
ans[a[]+a[]]=;
ans[a[]+a[]]=;
ans[a[]+a[]]=;
ans[a[]+a[]+a[]]=;
ans[a[]+a[]+a[]]=;
ans[a[]+a[]+a[]]=;
ans[a[]+a[]+a[]]=;
ans[a[]+a[]+a[]]=;
ans[a[]+a[]+a[]]=;
int q;
scanf("%d",&q);
while(q--)
{
string k="";
scanf("%s",str[]);
int len=strlen(str[]);
for(int i=;i<len;i++)
{
if(str[][i]>='a'&&str[][i]<='z')
k+=str[][i];
if(str[][i]>='A'&&str[][i]<='Z')
k+=str[][i]-'A'+'a';
}
if(ans[k])
printf("ACC\n");
else
printf("WA\n");
}
return ;
}
C. Capture Valerian
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.

Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.

Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.

Each door has 4 parts. The first part is an integer number a. The second part is either an integer number b or some really odd sign which looks like R. The third one is an integer c and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.

c is an integer written in base a, to open the door we should write it in base b. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!

Here's an explanation of this really weird number system that even doesn't have zero:

Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.:

  • I=1
  • V=5
  • X=10
  • L=50
  • C=100
  • D=500
  • M=1000

Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1, 000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80;CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.

Also in bases greater than 10 we use A for 10, B for 11, etc.

Help Shapur capture Valerian and bring peace back to Persia, especially Armenia.

Input

The first line contains two integers a and b (2 ≤ a, b ≤ 25). Only b may be replaced by an R which indicates Roman numbering system.

The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103.

It is guaranteed that if we have Roman numerals included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510.

Output

Write a single line that contains integer c in base b. You must omit leading zeros.

Examples
input
10 2
1
output
1
input
16 R
5
output
V
input
5 R
4
output
IV
input
2 2
1111001
output
1111001
input
12 13
A
output
A
Note

You can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals

题意:进制转换,a为当前数的进制数,转化为b,R为罗马数字;

思路:模拟;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=2e5+,M=1e6+,inf=1e9+;
const ll INF=1e18+,mod=;
char b[];
char num[N];
ll c(char a)
{
if(a>='A'&&a<='Z')
return a-'A'+;
return a-'';
}
char c2(ll x)
{
if(x<)
return x+'';
return x-+'A';
}
string ans;
int main()
{
ll a;
scanf("%lld%s",&a,b);
scanf("%s",num);
ll base=,p=;
int x=strlen(num);
for(int i=x-;i>=;i--,base*=a)
p+=c(num[i])*base;
if(b[]=='R')
{
int n4=p/;
p%=;
int n3=p/;
p%=;
int n2=p/;
int n1=p%;
for(int i=;i<n4;i++)
ans+='M';
if(n3==)
ans+="CM";
else if(n3==)
ans+="CD";
else if(n3>=)
ans+="D";
if(n3%!=)
for(int i=;i<n3%;i++)
ans+='C';
if(n2==)
ans+="XC";
else if(n2==)
ans+="XL";
else if(n2>=)
ans+="L";
if(n2%!=)
for(int i=;i<n2%;i++)
ans+='X';
if(n1==)
ans+="IX";
else if(n1==)
ans+="IV";
else if(n1>=)
ans+="V";
if(n1%!=)
for(int i=;i<n1%;i++)
ans+='I';
cout<<ans<<endl;
}
else
{
int q=;
for(int i=strlen(b)-,j=;i>=;i--,j*=)
q+=c(b[i])*j;
while(p)
{
ans+=c2(p%q);
p/=q;
}
reverse(ans.begin(),ans.end());
cout<<ans<<endl;
if(ans.size()==)
cout<<<<endl;
}
return ;
}
D. Eternal Victory
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal!

He decided to visit all n cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these n cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities.

All cities are numbered 1 to n. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city.

Help Shapur find how much He should travel.

Input

First line contains a single natural number n (1 ≤ n ≤ 105) — the amount of cities.

Next n - 1 lines contain 3 integer numbers each xiyi and wi (1 ≤ xi, yi ≤ n, 0 ≤ wi ≤ 2 × 104). xi and yi are two ends of a road and wiis the length of that road.

Output

A single integer number, the minimal length of Shapur's travel.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Examples
input
3
1 2 3
2 3 4
output
7
input
3
1 2 3
1 3 3
output
9

题意:给你一棵树,n个节点,1为根遍历这颗树走的最小的权值;

思路:总权值*2-max一条链;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-7
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=;
struct is
{
int v,w,nex;
}edge[N<<];
int head[N<<],edg;
ll ans,maxx;
void init()
{
memset(head,-,sizeof(head));
ans=maxx=edg=;
}
void add(int u,int v,int w)
{
edg++;
edge[edg].v=v;
edge[edg].w=w;
edge[edg].nex=head[u];
head[u]=edg;
}
void dfs(int x,int fa,ll val)
{
//cout<<x<<endl;
maxx=max(maxx,val);
for(int i=head[x];i!=-;i=edge[i].nex)
{
int v=edge[i].v;
int w=edge[i].w;
if(v==fa)continue;
dfs(v,x,val+w);
}
}
int main()
{
init();
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
ans+=w;
}
dfs(,-,);
cout<<ans*-maxx<<endl;
return ;
}
/*
3
1 2 3
2 3 3
*/
E. Enemy is weak
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The Romans have attacked again. This time they are much more than the Persians but Shapur is ready to defeat them. He says: "A lion is never afraid of a hundred sheep".

Nevertheless Shapur has to find weaknesses in the Roman army to defeat them. So he gives the army a weakness number.

In Shapur's opinion the weakness of an army is equal to the number of triplets i, j, k such that i < j < k and ai > aj > ak where ax is the power of man standing at position x. The Roman army has one special trait — powers of all the people in it are distinct.

Help Shapur find out how weak the Romans are.

Input

The first line of input contains a single number n (3 ≤ n ≤ 106) — the number of men in Roman army. Next line contains n different positive integers ai (1 ≤ i ≤ n, 1 ≤ ai ≤ 109) — powers of men in the Roman army.

Output

A single integer number, the weakness of the Roman army.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Examples
input
3
3 2 1
output
1
input
3
2 3 1
output
0
input
4
10 8 3 1
output
4
input
4
1 5 4 3
output
1

题意:找三元组;

思路:枚举中点,找前面比其大的个数x,后面比其小的个数y,贡献就为x*y;  

   树状数组+离散化即可;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-7
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=;
int tree[M];
int lowbit(int x)
{
return x&-x;
}
void update(int x,int c)
{
while(x<M)
{
tree[x]+=c;
x+=lowbit(x);
}
}
int query(int x)
{
int sum=;
while(x)
{
sum+=tree[x];
x-=lowbit(x);
}
return sum;
}
int s[M],a[M],len;
ll pre[M],nex[M];
int getnum(int x)
{
int pos=lower_bound(s+,s++len,x)-s;
return pos;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
s[i]=a[i];
}
sort(s+,s+n+);
len=unique(s+,s++n)-s-;
for(int i=;i<=n;i++)
a[i]=getnum(a[i]);
for(int i=;i<=n;i++)
{
update(a[i],);
pre[i]=query(M-)-query(a[i]);
}
memset(tree,,sizeof(tree));
for(int i=n;i>=;i--)
{
update(a[i],);
nex[i]=query(a[i]-);
}
ll ans=;
for(int i=;i<=n;i++)
{
ans+=nex[i]*pre[i];
}
cout<<ans<<endl;
return ;
}
A. Ultra-Fast Mathematician
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.

One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.

In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.

Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞(length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.

Now you are going to take part in Shapur's contest. See if you are faster and more accurate.

Input

There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.

Output

Write one line — the corresponding answer. Do not omit the leading 0s.

Examples
input
1010100
0100101
output
1110001
input
000
111
output
111
input
1110
1010
output
0100
input
01110
01100
output
00010

Codeforces Beta Round #57 (Div. 2) A,B,C,D,E的更多相关文章

  1. Codeforces Beta Round #57 (Div. 2)

    Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...

  2. Codeforces Beta Round #57 (Div. 2) E. Enemy is weak

    求满足条件的三元组的个数,可以转换求一元组和二元组组成的满足条件的三元组的个数,且对于(x),(y,z),x > y,且x出现的p_x < p_y. x可直接枚举O(n),此时需要往后查询 ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. 企业服务的3种模式:On-Premise、SaaS、Mixed,该选哪种?--创业邦

    B轮融资二三事 我们从9月份开始启动B轮融资,与这些颇具洞察力的投资人聊天,是非常有挑战的事.他们的很多观点充满智慧,能帮你突破思考局限,受益良多.当然,整个过程虽然有趣但也不轻松,毕竟你的目的是完成 ...

  2. C语言实现日历输出

    这个还是挺实用的.... 头文件: #ifndef MAIN_H #define MAIN_H #include "stdio.h" #include "math.h&q ...

  3. MP3 ID3信息编辑器(附源码)

    练习WPF时写的编辑MP3 ID3信息的小工具,方便对歌曲的统一管理,同时增加了调用豆瓣音乐API获取专辑信息的功能:1.主界面: 2.没有ID3 信息的MP3歌曲: 3.点击自动获取,从豆瓣音乐获取 ...

  4. 比特币BTC全节点搭建

    比特币BTC全节点搭建 #环境 ubuntu 16.4 #硬盘500GB #截止2018-12-31磁盘占用超过230GB #客户端安装 #下载页面 #https://bitcoin.org/zh_C ...

  5. JQuery的Ajax跨域请求的解决方式

            今天在项目中须要做远程数据载入并渲染页面,直到开发阶段才意识到ajax跨域请求的问题,隐约记得Jquery有提过一个ajax跨域请求的解决方式,于是即刻翻出Jquery的API出来研究 ...

  6. Mysql5.7.10新加用户

    INSERT INTO mysql.user(HOST,USER,authentication_string,ssl_cipher,x509_issuer,x509_subject,select_pr ...

  7. pssh批量远程管理工具

    Linux下批量管理工具pssh使用记录   pssh是一款开源的软件,使用python实现,用于批量ssh操作大批量机器:pssh是一个可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具 ...

  8. POJ1236:Network of Schools(tarjan+缩点)?

    题目: http://poj.org/problem?id=1236 [题意] N(2<N<100)各学校之间有单向的网络,每个学校得到一套软件后,可以通过单向网络向周边的学校传输,问题1 ...

  9. jquery map方法使用示例

    jquery的map方法非常好用,其作用是将数组或单个对象,替换为新的内容 感觉jquery的map方法非常好用. 方法作用:将数组或单个对象,替换为新的内容.  应用实例:获取一组checkbox的 ...

  10. Linux系统——Ansible批量管理工具

    批量管理工具: (1)ansible 操作简单(适用于500台以下服务器) (2)saltstack 比较复杂(一般适用于1000-4w台服务器) (3)puppet超级复杂 systemctl(统一 ...