ACM-ICPC 2018 沈阳赛区网络预赛 D F I G K持续更新中

/**
G. Spare Tire
链接:https://nanti.jisuanke.com/t/31448
题意:由递推式可得到数列的第n项为n*(n+1),前n项和为n*(n+1)*(2*n+1)/6+n*(n+1)/2;
枚举m的质因子,通过容斥找出[1,n]中与m不互质的数
对于m的每个质因数组合y  可以得到最大和其不互质的数 m/y*y  最后依据容斥原理 奇加偶减冗余一下即可
*******tricks******
取余长度过长 wa....了一下午...O(1)直接ans wa
*/

#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef unsigned long long LL;

const int maxn = 1e6 + 10;
LL arr[maxn];
int p;
LL inv6,inv2;
LL quick(LL x,LL y){
    LL ans= 1;
    while(y){
        if(y&1)ans=ans*x%mod;
        y=y>>1;
        x=x*x%mod;
    }
    return ans;
}
/**
4 4
9876543 1234567
*/

LL get(LL x, LL y) {
    LL cnt = x / y;
    LL tmp=y*y%mod;
    tmp=tmp*cnt%mod*(cnt+1)%mod*(2*cnt+1)%mod*inv6;
    tmp=(tmp+y*cnt%mod*(cnt+1)%mod*inv2)%mod;
    return tmp;
}

void getp(LL n) {  //分解质因子
    p = 0;
    for(int i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            arr[p++] = i;
            while(n % i == 0) n /= i;
        }
    }
    if(n > 1) arr[p++] = n;
}

int main() {
    LL n,m;
    inv6=quick(6ll,mod-2);
    inv2=quick(2ll,mod-2);
    while(~scanf("%lld %lld", &n,&m)) {
        getp(m);
        LL sum = n * (n + 1)%mod * (2 * n + 1)%mod*inv6%mod+n*(n+1)%mod*inv2%mod;
        LL ans = 0;
        for(int i = 1; i < (1 << p); i++) { //状压
            LL res = 0, cnt = 1;
            for(int j = 0; j < p; j++) {
                if(i & (1 << j)) {
                    cnt *= arr[j];
                    res++;
                }
            }
            if(res & 1) ans =(ans+get(n, cnt))%mod; //容斥
            else ans = (ans-get(n, cnt)+mod)%mod;
        }
        sum=(sum-ans+mod)%mod;
        printf("%lld\n",sum);
    }
    return 0;
}

容斥的第二种写法;

LL ans;
void dfs(int step,int flag,int tmp,ll x){
	if(step==p){
		ans=(ans+mod+flag*get(x,tmp))%mod;
		return ;
	}
	dfs(step+1,flag,tmp,x);
	dfs(step+1,-flag,lcm(tmp,arr[step]),x);
}

int main() {
	LL n,m;
    inv6=quick(6ll,mod-2);
    inv2=quick(2ll,mod-2);
    while(~scanf("%lld %lld", &n,&m)) {
        getp(m);
	    ans = 0;
        dfs(0,1,1,n);
        printf("%lld\n",ans);
    }
    return 0;
}

/**
 F :Fantastic Graph
链接:https://nanti.jisuanke.com/t/31447
最大流模板题;
*/

#include<cstdio>
#include<cstring>
using namespace std;
const int inf=1<<30;
const int nmax=100105;//点的数量
const int mmax=3000005;//边的数量
struct node
{
	int c,u,v,next;
	void insert(int nu,int nv,int nc,int nnext)
	{
		u=nu;
		v=nv;
		c=nc;
		next=nnext;
	}
}edge[mmax];
int cnt,head[nmax];
int cur[nmax],ps[nmax],dep[nmax];

void addedge(int u,int v,int w) //加边
{
	edge[cnt].insert(u,v,w,head[u]);
	head[u]=cnt++;
	edge[cnt].insert(v,u,0,head[v]);
	head[v]=cnt++;
}

int dinic(int s, int t){                       //  dinic
    int tr, res = 0;
    int i, j, k, f, r, top;
    while(1){
        memset(dep, -1, sizeof(dep));
        for(f = dep[ps[0]=s] = 0, r = 1; f != r;)
        {
            for(i = ps[f ++], j = head[i]; j; j = edge[j].next)
            {
                if(edge[j].c && dep[k=edge[j].v] == -1)
                {
                    dep[k] = dep[i] + 1;
                    ps[r ++] = k;
                    if(k == t)
                    {
                        f = r; break;
                    }
                }
            }
        }
        if(dep[t] == -1) break;
        memcpy(cur, head, sizeof(cur));
        i = s, top = 0;
        while(1)
        {
            if(i == t)
            {
                for(tr =inf, k = 0; k < top; k ++)
                {
                    if(edge[ps[k]].c < tr)
                    {
                        tr = edge[ps[f=k]].c;
                    }
                }
                for(k = 0; k < top; k ++)
                {
                    edge[ps[k]].c -= tr;
                    edge[ps[k]^1].c += tr;
                }
                i = edge[ps[top=f]].u;
                res += tr;
            }
            for(j = cur[i]; cur[i]; j = cur[i] =edge[cur[i]].next)
            {
                if(edge[j].c && dep[i]+1 == dep[edge[j].v])
                {
                	break;
                }
            }
            if(cur[i])
            {
                ps[top ++] = cur[i];
                i = edge[cur[i]].v;
            }
            else
            {
                if(top == 0)
                {
                	break;
                }
                dep[i] = -1;
                i = edge[ps[-- top]].u;
            }
        }
    }
    return res;
}

int main()
{
    int l,r,m,x,y,s,t,S,T,u,v,ooo=1;
    while(~scanf("%d%d%d",&l,&r,&m)){
        printf("Case %d: ",ooo++);
        cnt=2;
        memset(head,0,sizeof(head));
        scanf("%d%d",&x,&y);
        while(m--){
            scanf("%d%d",&u,&v);
            addedge(u,v+l,1);
        }
        s=0,t=l+r+1;
        S=l+r+2,T=l+r+3;
        for(int i=1;i<=l;i++){
            addedge(s,i,y-x);
            addedge(S,i,x);
            addedge(s,T,x);
        }
        addedge(t,s,inf);
        for(int i=1;i<=r;i++){
            addedge(i+l,t,y-x);
            addedge(S,t,x);
            addedge(i+l,T,x);
        }
        if(dinic(S,T)==(l+r)*x)
            printf("Yes\n");
        else printf("No\n");
    }
}
/**
I Lattice's basics in digital electronics 
链接:https://nanti.jisuanke.com/t/31450
题意:可仔细阅读case2 的模拟过程;
大模拟.....先进行转换后转换回去,处理好合法串的情况,注意查询输出即可;
********tricks******
str+=s the time << str=str+s;
赛中并没有看到这个题,遗憾;
*/

#include<bits/stdc++.h>
#define ll long long
using namespace std;

map<string,int>mp1;
map<char,string>mp2;
string s1,str,s2,s3,tmp;

int main (){
    mp2['0']="0000";
    mp2['1']="0001";
    mp2['2']="0010";
    mp2['3']="0011";
    mp2['4']="0100";
    mp2['5']="0101";
    mp2['6']="0110";
    mp2['7']="0111";
    mp2['8']="1000";
    mp2['9']="1001";
    mp2['A']="1010";
    mp2['B']="1011";
    mp2['C']="1100";
    mp2['D']="1101";
    mp2['E']="1110";
    mp2['F']="1111";

    mp2['a']="1010";
    mp2['b']="1011";
    mp2['c']="1100";
    mp2['d']="1101";
    mp2['e']="1110";
    mp2['f']="1111";
    int t;scanf("%d",&t);
    int x;
    while(t--){
        int n,m,cnt2;scanf("%d %d",&n,&m);
        mp1.clear();s1="";s2="";tmp="";
        for(int i=0;i<m;i++){
            cin>>x>>str;
            mp1[str]=x;
        }
        cnt2=0;
        cin>>str;int l=str.length();
        for(int i=0;i<l;i++) s1+=mp2[str[i]];
        for(int i=0;i<4*l;i+=9){
            s3=s1.substr(i,9);
            if(s3.length()!=9) break;
            int cnt=0;
            for(int j=0;j<8;j++) {
                if(s3[j]=='1') cnt++;
            }
            if((cnt%2==1)&&s1[i+8]=='0') s2+=s3.substr(0,8);
            if((cnt%2==0)&&s1[i+8]=='1') s2+=s3.substr(0,8);
            s3="";
        }
        int len=s2.length();
        int k=0;
        for(int i=0;i<len;i++){
            tmp+=s2[i];
            if(mp1[tmp]) {
                int x=mp1[tmp];
                printf("%c",(char)x);
                tmp="";
                k++;
            }
            if(k==n) break;
        }
        cout<<endl;
    }
    return 0;
}
/***
 K. Supreme Number
链接:https://nanti.jisuanke.com/t/31452
题意:求1-->n最大的数&&该数的子序列组合后为质数;
打表即可;;
******tricks****
基本语法;......
*/

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int a[100]={2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317};

int main (){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t;cin>>t;
	string str;
	for(int cas=1;cas<=t;cas++){
		cin>>str;
		int len=str.length();
		if(len>=4) printf("Case #%d: 317\n",cas);
		else {
			int ans=0,len=str.length();
			for(int i=0;i<len;i++) ans=ans*10+(str[i]-'0');
			if(ans>=317) { printf("Case #%d: 317\n",cas);}
			else for(int i=0;i<=19;i++){
				if(a[i]>ans) { printf("Case #%d: %d\n",cas,a[i-1]);break;}
				else if(a[i]==ans) { printf("Case #%d: %d\n",cas,a[i]);break;}
			}
		}
	}
	return 0;
}
/**
D. Made In Heaven
链接:https://nanti.jisuanke.com/t/31445
题意:是否存在第k短路且长度是否小于等于T.
思路:*A + dijstra +堆优化 模板题,原题;
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int maxn = 10000 + 5;
const int INF = 0x3f3f3f3f;
int s, t, k;

bool vis[maxn];
int dist[maxn];

struct Node {
    int v, c;
    Node (int _v = 0, int _c = 0) : v(_v), c(_c) {}
    bool operator < (const Node &rhs) const {
        return c + dist[v] > rhs.c + dist[rhs.v];
    }
};

struct Edge {
    int v, cost;
    Edge (int _v = 0, int _cost = 0) : v(_v), cost(_cost) {}
};

vector<Edge>E[maxn], revE[maxn];

void Dijkstra(int n, int s) {
    memset(vis, false, sizeof(vis));
    for (int i = 1; i <= n; i++) dist[i] = INF;
    priority_queue<Node>que;
    dist[s] = 0;
    que.push(Node(s, 0));
    while (!que.empty()) {
        Node tep = que.top(); que.pop();
        int u = tep.v;
        if (vis[u]) continue;
        vis[u] = true;
        for (int i = 0; i < (int)E[u].size(); i++) {
            int v = E[u][i].v;
            int cost = E[u][i].cost;
            if (!vis[v] && dist[v] > dist[u] + cost) {
                dist[v] = dist[u] + cost;
                que.push(Node(v, dist[v]));
            }
        }
    }
}

int astar(int s) {
    priority_queue<Node> que;
    que.push(Node(s, 0)); k--;
    while (!que.empty()) {
        Node pre = que.top(); que.pop();
        int u = pre.v;
        if (u == t) {
            if (k) k--;
            else return pre.c;
        }
        for (int i = 0; i < (int)revE[u].size(); i++) {
            int v = revE[u][i].v;
            int c = revE[u][i].cost;
            que.push(Node(v, pre.c + c));
        }
    }
    return -1;
}

void addedge(int u, int v, int w) {
    revE[u].push_back(Edge(v, w));
    E[v].push_back(Edge(u, w));
}

int main() {
    int n, m, u, v, w,yyy;
    while (scanf("%d%d", &n, &m) != EOF) {
        for (int i = 0; i <= n; i++) {
            E[i].clear();
            revE[i].clear();
        }
        scanf("%d%d%d%d", &s, &t, &k,&yyy);
        for (int i = 0; i < m; i++) {
            scanf("%d%d%d", &u, &v, &w);
            addedge(u, v, w);
        }

        Dijkstra(n, t);
        if (dist[s] == INF) {
            puts("Whitesnake!");
            continue;
        }
        if (s == t) k++;
        if(astar(s)<=yyy)puts("yareyaredawa");
        else puts("Whitesnake!");
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值