设为首页 加入收藏

TOP

Codeforces Round #287 (Div. 2)A,B,C,D,E(二)
2015-07-20 17:23:46 来源: 作者: 【 】 浏览:4
Tags:Codeforces Round #287 Div.
他是否已经存在后缀串整除了,0代表不存在,1代表存在。

D. The Maths Lecture time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.

First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x?>?0 exist such that:

  • Decimal representation of x (without leading zeroes) consists of exactly n digits;
  • There exists some integer y?>?0 such that:
    • \;
    • decimal representation of y is a suffix of decimal representation of x.

      As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.<??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+CkNhbiB5b3UgaGVscCBBbXIgZXNjYXBlIHRoaXMgZW1iYXJyYXNzaW5nIHNpdHVhdGlvbj88L3A+CgoKCklucHV0CjxwPgpJbnB1dCBjb25zaXN0cyBvZiB0aHJlZSBpbnRlZ2VycyA8ZW0+bjwvZW0+LD88ZW0+azwvZW0+LD88ZW0+bTwvZW0+ICgxP6HcPzxlbT5uPC9lbT4/odw/MTAwMCwgMT+h3D88ZW0+azwvZW0+P6HcPzEwMCwgMT+h3D88ZW0+bTwvZW0+P6HcPzEwOSkuPC9wPgoKCgpPdXRwdXQKPHA+ClByaW50IHRoZSByZXF1aXJlZCBudW1iZXIgbW9kdWxvIDxlbT5tPC9lbT4uPC9wPgoKCgpTYW1wbGUgdGVzdChzKQoKCgppbnB1dAo8cHJlIGNsYXNzPQ=="brush:java;">1 2 1000

output
4
input
2 2 1000
output
45
input
5 3 1103
output
590
Note

A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.

#include 
        
         
#include 
         
           #include 
          
            #include 
           
             #include 
            
              #include 
             
               #include 
              
                #include 
               
                 #include 
                
                  #include 
                 
                   #include 
                  
                    #include 
                    #include 
                    
                      #define eps 1e-9 ///#define M 1000100 ///#define LL __int64 #define LL long long ///#define INF 0x7ffffff #define INF 0x3f3f3f3f #define PI 3.1415926535898 #define zero(x) ((fabs(x)
                     
                      >= 1; } return b; } int main() { LL n, k, m; while(cin >>n>>k>>m) { memset(dp, 0, sizeof(dp)); dp[0][0][0] = 1; for(int i = 1; i <= n; i++) { int j = 0; if(i == n) j++; for(; j < 10; j++) { for(int sk = 0; sk < k; sk++) { ///LL xp = (sk+j*10LL)%k; LL xp = (pow_mod(10LL,i-1,k)*j%k+sk)%k; if(!xp && j) dp[i][xp][1] += dp[i-1][sk][0]; else dp[i][xp][0] += dp[i-1][sk][0]; dp[i][xp][1] %= m; dp[i][xp][0] %= m; dp[i][xp][1] += dp[i-1][sk][1]; dp[i][xp][1] %= m; } } } LL ans = 0; for(int i = 0; i < k; i++) { ans += dp[n][i][1]; ans %= m; } cout<
                      
                       
E这题感觉比D题简单,就是有n个城市,m条边。让你求出来1到n的最短路,但是要求,保证最短路的时候,要求权值最大。

E. Breaking Good time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Breaking Good is a new video game which a lot of gamers want to have. There is a certain level in the game that is really difficult even for experienced gamers.

Walter William, the main character of the game, wants to join a gang called Los Hermanos (The Brothers). The gang controls the whole country which consists of n cities with m bidirectional roads connecting them. There is no road is connecting a city to itself and for any two cities there is at most one road between them. The country is connected, in the other words, it is possible to reach any city from any other city using the given roads.

The roads aren't all working. There are some roads which need some more work to be performed to be completely functioning.

The gang is going to rob a bank! The bank is located in city 1. As usual, the hardest part is to escape to their headquarters where the police can't get them. The gang's headquarters is in city n. To gain the gang's trust, Walter is in charge of this operation, so he came up with a smart plan.

First of all the path which they are going to use on their way back from city 1 to their headquarters n must be as short as possible, since it is important to finish operation as fast as possible.

Then, gang has to blow up all other roads in country that don't lay on this path, in order to prevent any police reinforcements. In case of non-working road, they don't have to blow up it as it is already malfunctional.

If the chosen path has some roads that doesn't work they'll have to repair those roads before the operation.

Walter discovered that there was a lot of paths that satisfied the condition of being shortest possible so he decided to choose among them a path that minimizes the total number of affected roads (both roads that have to be blown up and roads to be repaired).

Can you help Walter complete his task and gain the gang's trust?

Input

The first line of input contains two integers n,?m (2?≤?n?≤?105, \), the number of cities and number of roads respectively.

In following m lines there are descriptions of roads. Each description consists of three integers x,?y,?z (1?≤?x,?y?≤?n, \) meaning that there is a road connecting cities number x and y. If z?=?1, this road is working, otherwise it is not.

Output

In the first line output one integer k, the minimum possible number of roads affected by gang.

In the following k lines output three integers describing roads that should be affected. Each line should contain three integers x,?y,?z (1?≤?x,?y?≤?n, \), cities connected by a road and the new state of a road. z?=?1 indicates that the road between cities x and yshould be repaired and z?=?0 means that road should be blown up.

You may output roads in any order. Each affected road should appear exactly once. You may output cities connected by a single road in any order. If you output a road, it"s original state should be different from z.

After performing all operations accroding to your plan, there should remain working only roads lying on some certain shortest past between city 1 and n.

If there are multiple optimal answers output any.

Sample test(s) input
2 1
1 2 0
output
1
1 2 1
input
4 4
1 2 1
1 3 0
2 3 1
3 4 1
output
3
1 2 0
1 3 1
2 3 0
input
8 9
1 2 0
8 3 0
2 3 1
1 4 1
8 7 0
1 5 1
4 6 1
5 7 0
6 8 0
output
3
2 3 0
1 5 0
6 8 1
Note

In the first test the only path is 1?-?2

In the second test the only shortest path is 1?-?3?-?4

In the third test there are multiple shortest paths but the optimal is 1?-?4?-?6?-?8

#include 
                        
                         
#include 
                         
                           #include 
                          
                            #include 
                           
                             #include 
                            
                              #include 
                             
                               #include 
                              
                                #include 
                               
                                 #include 
                                
                                  #include 
                                 
                                   #include 
                                  
                                    #include 
                                    #include 
                                    
                                      #define eps 1e-9 ///#define M 1000100 ///#define LL __int64 #define LL long long ///#define INF 0x7ffffff #define INF 0x3f3f3f3f #define PI 3.1415926535898 #define zero(x) ((fabs(x)
                                     
                                      que; int n = y; for(int i = 1; i <= n; i++) { p[i].dis = INF; p[i].dw = INF; } p[x].dis = 0; p[x].dw = 0; flag[x] = true; que.push(x); while(!que.empty()) { int sx = que.front(); flag[sx] = false; que.pop(); for(int i = head[sx]; i != -1; i = f[i].next) { int u = f[i].u; int w = f[i].w; if(p[u].dis > p[sx].dis+1) { p[u].dis = p[sx].dis+1; pre[u] = sx; xpre[u] = i; p[u].dw = p[sx].dw+w; if(flag[u]) continue; que.push(u); flag[u] = true; } else if(p[u].dis == p[sx].dis+1 && p[u].dw > p[sx].dw+w) { pre[u] = sx; xpre[u] = i; p[u].dw = p[sx].dw+w; if(flag[u]) continue; que.push(u); flag[u] = true; } } } int xp = n; while(xpre[xp] != -1) { vis[xpre[xp]] = 1; xp = pre[xp]; } } int main() { int n, m; while(cin >>n>>m) { init(); int x, y, z; for(int i = 0; i < m; i++) { scanf("%d %d %d", &x, &y, &z); if(z == 0) { add(x, y, z+2); continue; } add(x, y, z); } bfs(1, n); int ans = 0; for(int i = 0; i < cnt; i += 2) { int x = f[i].u; int y = f[i+1].u; if(x > y) swap(x, y); int w = f[i].w; if(vis[i] || vis[i+1]) { if(w == 2) { tp[ans].x = x; tp[ans].y = y; tp[ans++].z = 1; } } else { if(w == 1) { tp[ans].x = x; tp[ans].y = y; tp[ans++].z = 0; } } } cout<
                                      
                                       

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 2411Mondriaan's Dream 下一篇HDU 3342 Legal or Not

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python爬虫教程(从 (2025-12-26 16:49:14)
·【全269集】B站最详 (2025-12-26 16:49:11)
·Python爬虫详解:原 (2025-12-26 16:49:09)
·Spring Boot Java: (2025-12-26 16:20:19)
·Spring BootでHello (2025-12-26 16:20:15)