日常不会

链接:https://www.nowcoder.com/acm/contest/85/F

这道题需要想清楚每个图对应的x轴y轴、、

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<algorithm>
 7 using namespace std;
 8 typedef long long ll;
 9 const int maxn=2000+10;
10 const int maax=1e5+10;
11 int a[maax][5];
12 char s[maxn][5*maxn],w[maxn][maxn];
13 int main(){
14     int x,y,z,n;
15     cin>>x>>y>>z>>n;
16     for(int i=0;i<n;i++){
17         for(int j=0;j<3;j++)
18             cin>>a[i][j];
19     }
20     for(int i=0;i<y;i++){
21         for(int j=0;j<x;j++)
22             s[i][j]='.';
23     }
24     for(int i=0;i<y;i++)
25         s[i][x]=' ';
26     for(int i=0;i<y;i++){
27         for(int j=x+1;j<x+z+1;j++)
28             s[i][j]='.';
29     }
30     for(int i=0;i<n;i++){
31         s[y-1-(a[i][1]-1)][a[i][0]-1]='x';
32     }
33     for(int i=0;i<n;i++){
34         s[y-1-(a[i][1]-1)][x+1+(a[i][2]-1)]='x';
35     }
36     for(int i=0;i<z;i++){
37         for(int j=0;j<x;j++)
38             w[i][j]='.';
39     }
40     for(int i=0;i<n;i++){
41         w[a[i][2]-1][a[i][0]-1]='x';
42     }
43     for(int i=0;i<y;i++){
44         for(int j=0;j<x+z+1;j++)
45             cout<<s[i][j];
46         cout<<endl;
47     }
48     cout<<endl;
49     for(int i=0;i<z;i++){
50         for(int j=0;j<x;j++)
51             cout<<w[i][j];
52         cout<<endl;
53     }
54 }
View Code

链接:https://www.nowcoder.com/acm/contest/85/H

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<cstdlib>
 6 #include<algorithm>
 7 using namespace std;
 8 typedef long long ll;
 9 char s[10][5010];
10 char ans[5010];
11 int vis[5010];
12 int main(){
13     int n;
14     cin>>n;
15     for(int i=0;i<9;i++)
16         cin>>s[i];
17     for(int i=0;i<9;i++){
18         for(int j=0;j<n;j++){
19             if(s[i][j]=='o'){
20                 if(i ==0)ans[j]='F',vis[j]=1;
21                 if(i==1)ans[j]='E',vis[j]=1;
22                 if(i==2)ans[j]='D',vis[j]=1;
23                 if(i==3)ans[j]='C',vis[j]=1;
24                 if(i==4)ans[j]='B',vis[j]=1;
25                 if(i==5)ans[j]='A',vis[j]=1;
26                 if(i==6)ans[j]='G',vis[j]=1;
27                 if(i==7)ans[j]='F',vis[j]=1;
28                 if(i==8)ans[j]='E',vis[j]=1;
29             }
30             if(s[i][j]=='|')ans[j]='|',vis[j]=1;
31         }
32     }
33     for(int i=0;i<n;i++){
34         if(vis[i]==1)
35             cout<<ans[i];
36         else
37             cout<<" ";
38     }
39     cout<<endl;
40     return 0;
41 }
View Code

链接:https://www.nowcoder.com/acm/contest/85/

留给以后写吧。。

 1 //I-卡特兰数-组合数学-阶乘逆元快速幂
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<cmath>
 6 #include<cstdlib>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<vector>
10 using namespace std;
11 typedef long long ll;
12 const int maxn=2*1e5+10;
13 const int mod=998244353;
14 ll f[maxn];
15 void ff(){
16     f[0]=1;
17     for(int i=1;i<maxn;i++)
18         f[i]=(i*f[i-1])%mod;
19 }
20 ll poww(ll n,ll m){   //快速幂
21     ll ans=1;
22     while(m){
23         if(m&1)ans=(ans*n)%mod;
24         m=m>>1;
25         n=(n*n)%mod;
26     }
27     return ans;
28 }
29 ll cc(ll n,ll m){      //组合数
30     ll ans=f[n];
31     ans=(ans*poww(f[m],mod-2))%mod;
32     ans=(ans*poww(f[n-m],mod-2))%mod;
33     return ans;
34 }
35 int main(){
36     int t,n,m,h=0;
37     ff();
38     cin>>t;
39     while(t--){
40         cin>>n;
41         m=n-1;
42         ll ans=(cc(2*n,n)-cc(2*n,n-1)-cc(2*m,m)+cc(2*m,m-1)+2*mod)%mod;
43         cout<<"Case #"<<++h<<": "<<ans<<endl;
44     }
45 }
View Code

链接:https://www.nowcoder.com/acm/contest/85/G

以后再搞吧。。

                    C. Sonya and Robots
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.

Sonya has drawn nn numbers in a row, aiai is located in the ii-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.

Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one.

For example, if the numbers [1,5,4,1,3][1,5,4,1,3] are written, and Sonya gives the number 11 to the first robot and the number 44 to the second one, the first robot will stop in the 11-st position while the second one in the 33-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 44 to the first robot and the number 55 to the second one, they will meet since the first robot will stop in the 33-rd position while the second one is in the 22-nd position.

Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.

Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (pp, qq), where she will give pp to the first robot and qq to the second one. Pairs (pipi, qiqi) and (pjpj, qjqj) are different if pipjpi≠pj or qiqjqi≠qj.

Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.

Input

The first line contains a single integer nn (1n1051≤n≤105) — the number of numbers in a row.

The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1051≤ai≤105) — the numbers in a row.

Output

Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.

Examples
input
5
1 5 4 1 3
output
9
input
7
1 2 1 1 1 3 2
output
7
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
vector<int>q;
ll n,w;ll x[100002],y[100002];
int main()
{
        cin>>n;
        ll num=0;ll ans=0; 
        for(int i=0;i<n;i++)
        {
            cin>>w;q.push_back(w);
            x[w]++;
            if(x[w]==1) num++;//计算没有重复出现的数字 
        }
        for(int i=0;i<n;i++)//从左往右的过程 ,后面出现重复的数字会在前面就被遍历到然后就不会重复计算; 
        {
            x[q[i]]--;
            if(x[q[i]]==0) num--;
            if(y[q[i]]==0)
            {
                ans+=num;
                y[q[i]]=1;
            }
        }
        cout<<ans<<endl;
    return 0; 
}
View Code
                            C. Summarize to the Power of Two
 

  A sequence a1,a2,,ana1,a2,…,an is called good if, for each element aiai, there exists an element ajaj (iji≠j) such that ai+ajai+aj is a power of two (that is, 2d2d for some non-negative  integer dd).

  For example, the following sequences are good:

  • [5,3,11][5,3,11] (for example, for a1=5a1=5 we can choose a2=3a2=3. Note that their sum is a power of two. Similarly, such an element can be found for a2a2 and a3a3),
  • [1,1,1,1023][1,1,1,1023],
  • [7,39,89,25,89][7,39,89,25,89],
  • [][].

Note that, by definition, an empty sequence (with a length of 00) is good.

For example, the following sequences are not good:

  • [16][16] (for a1=16a1=16, it is impossible to find another element ajaj such that their sum is a power of two),
  • [4,16][4,16] (for a1=4a1=4, it is impossible to find another element ajaj such that their sum is a power of two),
  • [1,3,2,8,8,8][1,3,2,8,8,8] (for a3=2a3=2, it is impossible to find another element ajaj such that their sum is a power of two).

You are given a sequence a1,a2,,ana1,a2,…,an. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements.

Input

The first line contains the integer nn (1n1200001≤n≤120000) — the length of the given sequence.

The second line contains the sequence of integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109).

Output

Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all nn elements, make it empty, and thus get a good sequence.

Examples
input
6
4 7 1 5 4 9
output
1
input
5
1 2 3 4 5
output
2
input
1
16
output
1
数据太大,用暴力加法肯定超时。需要用一个map来匹配减去其中一个值,在输入中的数字能否找到就行了。不需要管元素是什么,只需要管个数。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 120000 + 10;
int a[maxn];
int p[maxn];
vector<int>V;
map<int,int>M;
int cnt = 0;
void init()
{
    for(int i = 0 ; i<=30 ; i++) p[i] = 1<<i; 
}
int main()
{
    int n;
    scanf("%d",&n);
    init();
    M.clear();
    for(int i = 0 ; i < n ; i++)
    {
        scanf("%d",&a[i]);
        if(!M.count(a[i]))
        {
            M[a[i]] = 1;
        }
        else 
        {
            M[a[i]] ++;
        }
    }
    int ans = 0;
    for(int i = 0 ; i < n ; i++)
    {
        int j;
        for(j = 0 ; j <= 30 ; j++)
        {
            int t = p[j] - a[i];
            if(t == a[i])
            {
                if(M[t]>=2)
                {
                    break;
                }
            }
            else 
            {
                if(M[t])
                {
                    break;
                }
            }
        }
        if(j == 31)
        {
            ans++;
        } 

    }
    cout<<ans<<endl;    
}
View Code
原文地址:https://www.cnblogs.com/txrtyy/p/8604569.html