Codeforces Beta Round #76 (Div. 2 Only)——A,B,C

A. Restoring Password
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".

Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.

Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.

Help Igor K. restore his ISQ account by the encrypted password and encryption specification.

Input

The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.

Output

Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.

水题,斟酌了半天,找了个string类函数过了。

string的子串:
string substr(int pos = 0,int n = npos) const;//返回pos开始的n个字符组成的字符串

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
using namespace std;
const int maxn=1000+5;
int main()
{
    string s,ss;
    map<string,int>q;
    cin>>s;
    //getchar();
    for(int i=0;i<=9;i++){
        cin>>ss;
        q[ss]=i;
    }
    for(int i=0;s[i];i+=10)
    {
        ss=s.substr(i,10);
        //cout<<ss<<endl;
        cout<<q[ss];
    }
    cout<<endl;
    return 0;
}

B. Friends
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.

The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"

Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" — he kept on repeating in his mind. — "Let's take, say, Max, Ilya, Vova — here, they all know each other! And now let's add Dima and Oleg to Vova — none of them is acquainted with each other! Now, that math is just rubbish!"

Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people.

Input

The first line contains an integer m (0 ≤ m ≤ 10), which is the number of relations of acquaintances among the five friends of Igor's.

Each of the following m lines contains two integers ai and bi (1 ≤ ai, bi ≤ 5;ai ≠ bi), where (ai, bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x.

Output

Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN".

题意理解了好久,判断所给图是否所有点首尾相接而成环即可。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
using namespace std;
const int maxn=1000+5;
int hash[maxn];
int main()
{
    int n;
    cin>>n;
    memset(hash,0,sizeof(hash));
    for(int i=0;i<n;i++){
        int u,v;
        cin>>u>>v;
        hash[u]++;hash[v]++;
    }
    bool flag=true;
    for(int i=1;i<=5;i++)
        if(hash[i]!=2) flag=false;
    if(flag) cout<<"FAIL";
    else cout<<"WIN";
    return 0;

C. Frames
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.

This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good.

Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, m icons can fit in a horizontal row in any window.

Igor K.'s computer contains n folders in the D: disk's root catalog. The folders are numbered from 1 to n in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from a to b inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from a to b and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders.

Input

The only line contains four integers nmab (1 ≤ n, m ≤ 1091 ≤ a ≤ b ≤ n). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.

Output

Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from a to b.

坑爹题。这道题直接挂到比赛结束。

特判的情况较多。

1.m=1时显然次数最小值为1.

2.b=n时特判:如果a在第一列或者a,b同行,次数为1,否则次数为2

3.所有a在第1列,b在最后一列的情况下或a,b同行,最小次数都是1.

4.a在第一列或b在最后一列或者a,b的列相邻(对角的两个矩形)或者a,b所在行相邻则次数为2

5.剩下的次数都是3.

#include <cstdio>
#include <iostream>
using namespace std;
const int maxn =1000+5;
int main()
{
    long long n,m,a,b;
    cin>>n>>m>>a>>b;
    int st=a/m+(a%m!=0);int ed=b/m+(b%m!=0);
    if(m==1){
        cout<<1;
        return 0;
    }
    if(b==n){
        if(a%m==1||st==ed) cout<<1;
        else cout<<2;
        return 0;
    }
    if((a%m==1&&b%m==0)||st==ed) {cout<<1;return 0;}
    if(a%m==1||b%m==0||st+1==ed||(b+1)%m==a%m) cout<<2;
    else cout<<3;
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值