ccf brush Inscription Ultimate Edition 03

This obviously did not last so smooth, since the third big question simulation actually stuck, leading to the collapse of mind, there is no mind to do forty-five ask, then post hoc analysis, I realized that only a small mistake small function, is really not a big deal, we can see the mentality is very important ah, deep breath

Opposite number 201403-1

Ideas: water problems, used to write their own functions abs, then forced statistics look like a

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e5+10;

bool ad[maxn];

int myabs(int a)
{
    if(a<0)
    {
        a = a * (-1);
    }
    return a;
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(ad,false,sizeof(ad));
        int num = 0;
        while(n--)
        {
            int temp;
            scanf("%d",&temp);
            if(ad[myabs(temp)])
            {
                num++;
            }
            else
            {
                ad[myabs(temp)] = true;
            }
        }
        printf("%d\n",num);
    }
    return 0;
}


201403-2 window

Ideas: At first glance, I felt a bit like a greedy or something very complex issue dp, after all, there are many issues to cover this, and then carefully after reading the title will find that in fact is not so complicated, since it is determined whether or not the point known inside the rectangle coordinates diagonal is a very easy thing, then the order is stored directly rectangle, then violence in order to determine just fine

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 110;

typedef struct POS
{
    int id;
    int x1;
    int x2;
    int y1;
    int y2;
}Pos;

Pos pos[maxn];

int main()
{
    int n,m;
    while(cin >> n >> m)
    {
        for(int i=1;i<=n;i++)
        {
            cin >> pos[n-i].x1 >> pos[n-i].y1 >> pos[n-i].x2 >> pos[n-i].y2;
            pos[n-i].id = i;
        }
        while(m--)
        {
            int x,y;
            cin >> x >> y;
            int now = 0;
            for(;now<n;now++)
            {
                if(   x >= pos[now].x1
                   && x <= pos[now].x2
                   && (
                        (y >= pos[now].y1 && y <= pos[now].y2)
                    ||  (y >= pos[now].y2 && y <= pos[now].y1)
                       )
                   )
                {
                    break;
                }
            }
            if(now == n)
            {
                cout << "IGNORED" << endl;
            }
            else
            {
                Pos re = pos[now];
                cout << re.id << endl;
                for(int i=now;i>0;i--)
                {
                    pos[i] = pos[i-1];
                }
                pos[0] = re;
            }
        }
    }
    return 0;
}


201403-3 command-line arguments

Thinking: This question is actually to be quite good to get started, read the string + typical judge, note format single-letter commands are easily overlooked

This time my whole card is actually a small function, not the end point coordinates substr second parameter passed, but a string of long, very uncomfortable

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 30;

bool in [maxn];
bool contain[maxn];

map<char,string> re;

string s;

/*bool legal(char a)
{
    if((a>='0'&&a<='9')||(a>='a'&&a<='z')||(a=='-'))
    {
        return true;
    }
    else
    {
        return false;
    }
}*/

int main()
{
    while(cin >> s)
    {
        memset(in,false,sizeof in);
        memset(contain,false,sizeof contain);
        int len = s.length();
        for(int i=0;i<len-1;i++)
        {
            in[s[i] - 'a'] = true;
            if(s[i+1] == ':')
            {
                contain[s[i]-'a'] = true;
                i++;
            }
        }
        if(s[len-1] != ':')
        {
            in[s[len-1]-'a'] = true;
        }
        int n;
        cin >> n;
        getchar();
        for(int i=1;i<=n;i++)
        {
            re.clear();
            string temp;
            getline(cin,temp);
            len = temp.length();
            int pos=0;
            while(pos<len&&temp[pos]!=' ')
            {
                pos++;
            }
            pos++;
            while(pos<len)
            {
                if(temp[pos] == '-')
                {
                    pos++;
                    if(pos>=len)
                    {
                        break;
                    }
                    char now = temp[pos];
                    if(now>'z'||now<'a')
                    {
                        break;
                    }
                    pos++;
                    if(pos>len)
                    {
                        break;
                    }
                    if(pos<len&&temp[pos]!=' ')
                    {
                        break;
                    }
                    if(in[now-'a'])
                    {
                        if(contain[now-'a'])
                        {
                            pos++;
                            int pos2 = pos;
                            //bool ok = true;
                            for(;pos2<len;pos2++)
                            {
                                if(temp[pos2] == ' ')
                                {
                                    break;
                                }
                               /* if(!legal(temp[pos2]))
                                {
                                    ok = false;
                                    break;
                                }*/
                            }
                            /*if(!ok)
                            {
                                break;
                            }*/
                            pos2--;
                            if(pos2<pos)
                            {
                                break;
                            }
                            string data = temp.substr(pos,pos2-pos+1);
                            re[now] = data;
                            pos = pos2+2;
                            continue;
                        }
                        else
                        {
                            re[now] = "*";
                            pos++;
                            continue;
                        }
                    }
                }
                break;
            }
            cout << "Case " << i << ":";
            map<char,string> :: iterator it;
            for(it = re.begin();it!=re.end();it++)
            {
                if(it->second == "*")
                {
                    cout << " -" << it->first;
                }
                else
                {
                    cout << " -" << it->first << " " << it->second;
                }
            }
            cout << endl;
        }
    }
    return 0;
}
/*
substr参数输错了
*/


Published 97 original articles · won praise 89 · views 20000 +

Guess you like

Origin blog.csdn.net/Owen_Q/article/details/79568846