ecjtu-summer training #8

A UVA - 725

输入一个数n求是否有abcde/fghij=n,abcdefghij都是不同的数字,有的全部输出,没有的就按格式输出。

暴力可以做时间为10!。

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #include <iomanip>
 6 #define ll long long
 7 using namespace std;
 8 int n, k, cnt, cnt1,res;
 9 int vis[1100];
10
11 int main(){
12     int kk = 1;
13     while(scanf("%d",&n)&&n) {
14         memset(vis,false,sizeof(vis));
15         int a,b,c,d,e,f,g,h,ii,jj,k = 0;
16         if(kk!=1)printf("\n");
17         for(int i = 1234; i <= 98765; i ++) {
18             memset(vis,0,sizeof(vis));
19             a = i%10,b = i/10%10,c = i/100%10,d = i/1000%10,e = i/10000%10;
20             int num = i*n;
21             if(num > 98765)break;
22             f = num%10,g = num/10%10,h = num/100%10,ii = num/1000%10,jj = num/10000%10;
23             vis[a]++;vis[b]++;vis[c]++;vis[d]++;vis[e]++;
24             vis[f]++;vis[g]++;vis[h]++;vis[ii]++;vis[jj]++;
25             int j;
26             for(j = 0; j < 10; j ++) {
27                 if(vis[j] > 1)break;
28             }
29             if(j == 10) {
30                 printf("%d%d%d%d%d / %d%d%d%d%d = %d\n",jj,ii,h,g,f,e,d,c,b,a,n);
31                 k++;
32             }else continue;
33         }
34         if(k == 0) printf("There are no solutions for %d.\n",n);
35         kk++;
36     }
37     return 0;
38 }

BHDU - 2546

电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。
某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。

Input多组数据。对于每组数据:

第一行为正整数n,表示菜的数量。n<=1000。

第二行包括n个正整数,表示每种菜的价格。价格不超过50。

第三行包括一个正整数m,表示卡上的余额。m<=1000。

n=0表示数据结束。

Output对于每组输入,输出一行,包含一个整数,表示卡上可能的最小余额。Sample Input

1
50
5
10
1 2 3 2 1 1 2 3 2 1
50
0

Sample Output

-45
32

背包问题,原题,先排序让最大的一个不做计算,剩下的求出可以组成最大不超过m-5的数,在把它减去不做计算的那个最大数就是答案了。

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 using namespace std;
 6 int v[1010];
 7 int dp[1010];
 8 int main(){
 9     int n,m,p;
10     while(scanf("%d",&n)&&n){
11         for(int i = 0; i < n; i ++)scanf("%d",&v[i]);
12         scanf("%d",&m);
13         sort(v,v+n);
14         for(int i = 0; i < n-1; i ++){
15             for(int k = m-5; k >= v[i]; k--){
16                 dp[k] = max(dp[k],dp[k-v[i]]+v[i]);
17             }
18         }
19         if(m < 5)printf("%d\n",m);
20         else printf("%d\n",m-dp[m-5]-v[n-1]);
21         memset(dp,0,sizeof(dp));
22         memset(v,0,sizeof(v));
23     }
24     return 0;
25 }

C CodeForces - 764A

Comrade Dujikov is busy choosing artists for Timofey‘s birthday and is recieving calls from Taymyr from Ilia-alpinist.

Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day consists of minutes 1,?2,?...,?z. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute.

Input

The only string contains three integers — n, m and z (1?≤?n,?m,?z?≤?104).

Output

Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.

Example

Input

1 1 10

Output

10

Input

1 2 5

Output

2

Input

2 3 9

Output

1

Note

Taymyr is a place in the north of Russia.

In the first test the artists come each minute, as well as the calls, so we need to kill all of them.

In the second test we need to kill artists which come on the second and the fourth minutes.

In the third test — only the artist which comes on the sixth minute.

原题。记下在z的范围的即是n的倍数又是m的倍数的数量。

#include <bits/stdc++.h>
using namespace std;
int a[10010],b[10010];
int main(){
    int n, m, z, ans = 0;
    cin >> n >> m >> z;
    for(int i = 1; i*n <= z; i++)
        a[i*n] = 1;
    for(int i = 1; i*m <= z; i ++)
        b[i*m] = 1;
    for(int i = 1; i <= z; i ++){
        if(a[i]==1 && b[i]==1)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

D CodeForces - 764C

Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci.

Now it‘s time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can.

Timofey doesn‘t like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn‘t consider the whole tree as a subtree since he can‘t see the color of the root vertex.

A subtree of some vertex is a subgraph containing that vertex and all its descendants.

Your task is to determine if there is a vertex, taking which in hands Timofey wouldn‘t be annoyed.

Input

The first line contains single integer n (2?≤?n?≤?105) — the number of vertices in the tree.

Each of the next n?-?1 lines contains two integers u and v (1?≤?u,?v?≤?n, u?≠?v), denoting there is an edge between vertices u and v. It is guaranteed that the given graph is a tree.

The next line contains n integers c1,?c2,?...,?cn (1?≤?ci?≤?105), denoting the colors of the vertices.

Output

Print "NO" in a single line, if Timofey can‘t take the tree in such a way that it doesn‘t annoy him.

Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.

Example

Input

41 22 33 41 2 1 1

Output

YES2

Input

31 22 31 2 3

Output

YES2

Input

41 22 33 41 2 1 2

Output

NO

又是一个原题,求是否有一个节点,当它成顶点时,它的每一个子节点下的节点们的颜色都一样。当有时,由于子节点下的节点们的颜色都一样,说明只有顶点和子节点的颜色不同,那么顶点出现的此数和相邻节点颜色不同的数量是一样的。
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 using namespace std;
 5 const int N = 1e5+10;
 6 int x[N], y[N], h[N], c[N];
 7 int main() {
 8     int n;
 9     scanf("%d",&n);
10     for(int i = 1; i < n; i ++) scanf("%d %d",&x[i],&y[i]);
11     for(int i = 1; i <= n; i ++) scanf("%d",&c[i]);
12     int m = 0;
13     for(int i = 1; i < n; i ++) {
14         if(c[x[i]] != c[y[i]]){
15             m++;
16             h[x[i]]++;h[y[i]]++;
17         }
18     }
19     for(int i = 1; i <= n; i ++){
20         if(h[i] == m){
21             return 0*printf("YES\n%d\n",i);
22         }
23     }
24     printf("NO\n");
25     return 0;
26 }

E UVA - 1640

比赛时一直输出很多区间,看规律,看不一个规律,不过没写出来。赛后去搜索了下题解。

题意:

  统计两个整数a,b之间各个数字(0~9)出现的次数,如1024和1032,他们之间的数字有1024 1025 1026 1027 1028 1029 1030 1031 1032 总共有10个0,10个1,3个3等等。

分析:

  因为前导0的干扰,为了计算方便暂时都先计算在内,之后再减;

  如果是0~199,那么百位上的0和1各出现一次,s剩下的就是两个00~99,总共两百个二位数,而每个数出现的次数都一样,都是2*(99-00+1)/10;

  那么任意的数都可以分解成类似的数字,如3426,则可以分成0000~2999,3000~3399,3400~3419,3420~3426几个部分各自计算,再求和按位减去前导0的个数。

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #define ll long long
 6 using namespace std;
 7 void Cal(char *s, int *num) {
 8     int i, j, k, t, m = atoi(s), n = strlen(s);
 9     for(i = k = 1; i < n; i ++)
10         k*=10,num[0]-=k;
11     for(i = 0; i < n; i ++, k/=10){
12         for(j = 0;j < s[i]-‘0‘; j ++)
13             num[j] += k;
14         for(t = 0; t < 10; t ++)
15             num[t] += k/10*(n-i-1)*j;
16         if(i+1 < n) num[j] += atoi(s+i+1);
17         num[j]++;
18     }
19 }
20 int main(){
21     char s[22];
22     int n,m,vis[11]={0},vis1[11]={0};
23     while(scanf("%d%d",&n,&m)){
24         if(n==0&&m==0)break;
25         if(n>m)swap(n,m);
26         memset(vis,0,sizeof(vis));
27         sprintf(s,"%d",n-1);
28         Cal(s,vis);
29         memset(vis1,0,sizeof(vis1));
30         sprintf(s,"%d",m);
31         Cal(s,vis1);
32         for(int i = 0; i < 10; i ++)
33             printf("%d%c",vis1[i]-vis[i],i==9?‘\n‘:‘ ‘);
34     }
35     return 0;
36 }
时间: 2024-10-06 04:26:44

ecjtu-summer training #8的相关文章

ECJTU 2018 Summer Training 2

Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did we not tell you that it was just an online game ? uhhh! now here is the real onsite task for Harry. You are given a magrid S ( a magic grid ) having

Android官方开发文档Training系列课程中文版:手势处理之滚动动画及Scroller

原文地址:http://android.xsoftlab.net/training/gestures/scroll.html 在Android中,滑动经常由ScrollView类来实现.任何超出容器边界的布局都应该将自己内嵌在ScrollView中,以便提供可滚动的视图效果.自定义滚动只有在特定的场景下才会被用到.这节课将会描述这样一种场景:使用scroller显示一种可滚动的效果. 你可以使用Scroller或者OverScroller来收集一些滑动动画所需要的数据.这两个类很相似,但是Ove

2017 UESTC Training for Data Structures

2017 UESTC Training for Data Structures A    水,找区间极差,RMQ怼上去. #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a;i<=b;i++) #define per(i,b,a) for (int i=b;i&

WeChall_Training: Programming 1 (Training, Coding)

When you visit this link you receive a message.Submit the same message back to http://www.wechall.net/challenge/training/programming1/index.php?answer=the_messageYour timelimit is 1.337 seconds 解题: 先在浏览器获取自己的cookie,再用python写了个自动提交的程序,header加上自己的cooki

Training的第二十天

今天接着做前天的活,就是实现把下载下来的jpg格式的图片设置为桌面的功能.要实现这个功能的关键点一个是要调用API(SystemParametersInfo)更换桌面:二是要把下载下来的JPG格式的图片转换成Bmp格式的图片才能够应用为桌面. 由于对API没什么概念,所以我从网上查了下资料并从网上copy了有关该API变成C#的代码和把jpg格式的图片转换成bmp格式图片的代码.接着看懂了里面的代码便自己修改了一下.接下来的是完善这个程序和把它加入到windows自动启动的任务中. 对于程序的完

2014 Multi-University Training Contest 6 Apple Tree(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 176    Accepted Submission(s): 120 Problem Description I've bought an orchard an

hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 188    Accepted Submission(s): 129 Problem Description I've bought an orchard an

xtu DP Training C.炮兵阵地

炮兵阵地 Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 118564-bit integer IO format: %lld      Java class name: Main 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P"表

2014 Super Training #1 F Passage 概率DP

原题: HDU 3366   http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排序,即P越大,Q越小就越好,这样可以确保先选最优的路走. dp[i][j]表示已经到了第i条路(说明前i-1条都没成功的情况),还剩j块钱时能够走出去的概率. 则方程: dp[i][j] = way[i].P + way[i].Q*(dp[i+1][j-1]) + way[i].D*(dp[i+1]

2014 UESTC Training for Data Structures H - Cookies Test

H - Cookies Test Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status As chief programmer at a cookie production plant you have many responsibilities, one of them being that the cookies produced and packag