2019 百度之星初赛 [01-04]

题目链接http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=862

 

1001:

对小的暴力枚举

#include
using namespace std;
typedef long long ll;
typedef complex comp;
const double pi = acos(-1);
const int mx = 1e5 + 10;
const int N = 1<<11;
int main()
{     
    int t;
    scanf("%d",&t);
    while(t--){
        int V;
        vector  g;
        scanf("%d",&V);
        int sum = 0 ,tmp = V;
        while(tmp){
            int d = tmp%10;
            sum += d;
            tmp /= 10;
        }
        int count = 0;
        for(int i=1;i<=sum;i++){
            if(sum%i==0&&V%i==0){
                count++;
                g.push_back(i);
            }
        }
        printf("%d\n",count);
        for(int i=0;i

1002:

还是暴力

#include
using namespace std;
typedef long long ll;
typedef complex comp;
const double pi = acos(-1);
const int mx = 1e5 + 10;
const int N = 1<<11;
char s[100],c[100];
int main()
{     
    int t;
    scanf("%d",&t);
    while(t--){
        int n,m;
        scanf("%d%d",&n,&m);
        int cnt[55][55];
        memset(cnt,0,sizeof(cnt));
        for(int i=1;i<=n;i++){
            scanf("%s%s",s,c);
            vector  g[30];
            for(int i=0;c[i];i++){
                g[c[i]-'a'].push_back(i+1);
            }
            for(int i=0;s[i];i++){
                for(int v:g[s[i]-'a'])
                    cnt[i+1][v]++;
            }
        }
        bool vis[55];
        memset(vis,0,sizeof(vis));
        vector  ans;
        for(int i=1;i<=m;i++){
            for(int j=1;j<=m;j++){
                if(cnt[i][j]==n&&!vis[j]){
                    ans.push_back(j);
                    vis[j] = 1; 
                    break;
                }
            }
        }
        if (ans.size()!=m) printf("-1\n");
        else{
            for(int i=0;i

1003:

考虑用^先分隔成若干段,然后每段的初始值为它的1的个数x,而且x最小变化为2,所以以二进制来看,除了第0位不会变,其它位可以在此二进制值之内随便取。

#include
using namespace std;
typedef long long ll;
typedef complex comp;
const double pi = acos(-1);
const int mx = (1<<21)+100;
char s[mx];
vector  g;
int main()
{     
    //cout << (1+1+1^2+2) << endl;
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%s",s+1);
        g.clear(); 
        int len = strlen(s+1);
        int pre = 0,cnt = 0;
        for(int i=1;s[i];i++){
            if(s[i]=='^'){
                g.push_back(i-pre);
                pre = i;
            }
        }
        g.push_back(len-pre+1);
        int ans = 0;
        int bit[30];
        memset(bit,0,sizeof(bit)); 
        for(int v:g){
            if(v&1) cnt += 1;
            for(int i=1;i<=21;i++)
            if(v&(1<=1;i--)
            if(bit[i]>1){
                ans |= (1<<(i+1))-2;
                break;
            }else if(bit[i]==1) ans |= (1<

1004:

2019 百度之星初赛 [01-04]_第1张图片

题解写的挺好的,我也不说了,剩下情况也很明显。

#include 
using namespace std;
const int mx = 2e5 + 10;
const int mod = 1e9+7;
typedef long long ll;
int a[mx];
ll fac[mx],inv[mx];
void init()
{
    inv[0] = fac[0] = 1;
    inv[1] = fac[1] = 1;
    for(int i=2;i

 

 

 

 

 

你可能感兴趣的:(DP,思维题)