CodeForces 450
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies.
Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
- Give m candies to the first child of the line.
- If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
- Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input
The first line contains two integers n, m(1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line contains n integers a1, a2, ..., an(1 ≤ ai ≤ 100).
Output
Output a single integer, representing the number of the last child.
Sample Input
- 5 2 1 3 1 4 2
- 4
- 6 4 1 1 2 2 3 3
- 6
Hint
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home.
题意:给出n个人,每个人需要ai颗糖站成一列,每次给列首发m颗糖,如果够就回家,如果不够就回到队尾继续排队。
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <queue>
- using namespace std;
- #define INF 0x3f3f3f3f
- #define N 110
- struct Node
- {
- int id,need;
- };
- int n,m;
- int main()
- {
- while(scanf("%d%d",&n,&m)!=EOF)
- {
- Node t;
- queue<Node> q;
- for(int i=;i<=n;i++)
- {
- t.id=i;
- scanf("%d",&t.need);
- q.push(t);
- }
- while(q.size()>)
- {
- t=q.front();
- q.pop();
- if(t.need>m)
- {
- t.need-=m;
- q.push(t);
- }
- }
- printf("%d\n",q.front().id);
- }
- return ;
- }
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Jzzhu has invented a kind of sequences, they meet the following property:
You are given x and y, please calculate fn modulo 1000000007(109 + 7).
Input
The first line contains two integers x and y(|x|, |y| ≤ 109). The second line contains a single integer n(1 ≤ n ≤ 2·109).
Output
Output a single integer representing fn modulo 1000000007(109 + 7).
Sample Input
- 2 3 3
- 1
- 0 -1 2
- 1000000006
Hint
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6).
题意:Fi=Fi-1+Fi-2,求Fn。
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- using namespace std;
- #define ll long long
- #define MOD 1000000007
- #define N 2
- struct Matric
- {
- ll size;
- ll a[N][N];
- Matric(ll s=)
- {
- size=s;
- memset(a,,sizeof(a));
- }
- Matric operator * (const Matric &t)
- {
- Matric res=Matric(size);
- for(ll i=;i<size;i++)
- {
- for(ll k=;k<size;k++)
- {
- if((*this).a[i][k])
- for(ll j=;j<size;j++)
- {
- res.a[i][j]=((res.a[i][j]+(*this).a[i][k]*t.a[k][j])%MOD+MOD)%MOD;
- //if(res.a[i][j]>=MOD) res.a[i][j]%=MOD;
- }
- }
- }
- return res;
- }
- Matric operator ^ (ll n)
- {
- Matric ans=Matric(size);
- for(ll i=;i<size;i++) ans.a[i][i]=;
- while(n)
- {
- if(n&) ans=ans*(*this);
- (*this)=(*this)*(*this);
- n>>=;
- }
- return ans;
- }
- void debug()
- {
- for(ll i=;i<size;i++)
- {
- for(ll j=;j<size;j++)
- {
- printf("%d ",a[i][j]);
- }
- printf("\n");
- }
- }
- };
- int main()
- {
- ll n,x,y;
- while(scanf("%lld%lld%lld",&x,&y,&n)!=EOF)
- {
- n--;
- Matric a=Matric();
- Matric b=Matric();
- a.a[][]=x;a.a[][]=y;
- b.a[][]=-;b.a[][]=;b.a[][]=;
- b=b^n;
- a=a*b;
- printf("%lld\n",a.a[][]);
- }
- return ;
- }
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
- each cut should be straight (horizontal or vertical);
- each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
- each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times.
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactlyk cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k(1 ≤ n, m ≤ 109; 1 ≤ k ≤ 2·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Sample Input
- 3 4 1
- 6
- 6 4 2
- 8
- 2 3 4
- -1
Hint
In the first sample, Jzzhu can cut the chocolate following the picture below:
In the second sample the optimal division looks like this:
In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
题意:一个n*m的巧克力需要切k刀,设最小面积为s,求最大s。如果不能切,输出-1
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <queue>
- using namespace std;
- #define ll long long
- #define INF 0x3f3f3f3f
- #define N 110
- ll ans;
- ll n,m,k;
- int main()
- {
- while(scanf("%lld%lld%lld",&n,&m,&k)!=EOF)
- {
- if(k>n+m-)
- {
- printf("-1\n");
- continue;
- }
- if(k<n || k<m)
- {
- ll k1=,k2=;
- if(k<n) k1=n/(k+)*m;
- if(k<m) k2=m/(k+)*n;
- ans=max(k1,k2);
- }
- else
- {
- ll k1=n/(k-(m-)+);
- ll k2=m/(k-(n-)+);
- ans=max(k1,k2);
- }
- printf("%lld\n",ans);
- }
- return ;
- }
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are mroads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One can use the i-th train route to go from capital of the country to city si (and vise versa), the length of this route is yi.
Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.
Input
The first line contains three integers n, m, k(2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105).
Each of the next m lines contains three integers ui, vi, xi(1 ≤ ui, vi ≤ n; ui ≠ vi; 1 ≤ xi ≤ 109).
Each of the next k lines contains two integers si and yi(2 ≤ si ≤ n; 1 ≤ yi ≤ 109).
It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.
Output
Output a single integer representing the maximum number of the train routes which can be closed.
Sample Input
- 5 5 3 1 2 1 2 3 2 1 3 3 3 4 4 1 5 5 3 5 4 5 5 5
- 2
- 2 2 3 1 2 2 2 1 3 2 1 2 2 2 3
- 2
题意:给出N个点,M条边的图,现在有L条铁路(铁路的起始点都为1)问最多可以去掉多少条铁路使得点1到其他的点的最短距离不变。
- #include <iostream>
- #include <cstdio>
- #include <queue>
- #include <cstring>
- using namespace std;
- #define INF 0x3f3f3f3f
- #define N 100010
- #define M 10*N
- struct Edge
- {
- int to,next,val;
- int flag;
- }edge[M];
- int ans;
- int tot;
- int n,m,k;
- int dis[N];
- int vis[N];
- int flag[N];
- int head[N];
- int mp[N];
- void init()
- {
- tot=;
- ans=;
- memset(mp,INF,sizeof(mp));
- memset(flag,,sizeof(flag));
- memset(head,-,sizeof(head));
- }
- void add(int u,int v,int w,int flag=)
- {
- edge[tot].to=v;
- edge[tot].val=w;
- edge[tot].flag=flag;
- edge[tot].next=head[u];
- head[u]=tot++;
- }
- void spfa(int s)
- {
- priority_queue<int> q; //不明白为啥改成优先队列就280ms ac
- for(int i=;i<=n;i++)
- {
- dis[i]=INF;
- vis[i]=;
- }
- dis[s]=;
- vis[s]=;
- q.push(s);
- while(!q.empty())
- {
- int u=q.top();
- q.pop();
- vis[u]=;
- for(int i=head[u];i!=-;i=edge[i].next)
- {
- int v=edge[i].to;
- int w=edge[i].val;
- if(dis[u]+w<=dis[v])
- {
- if(!flag[v] && edge[i].flag)
- {
- ans++;
- flag[v]=;
- }
- else if(flag[v] && !edge[i].flag)
- {
- ans--;
- flag[v]=;
- }
- if(dis[u]+w<dis[v] && !vis[v])
- {
- vis[v]=;
- q.push(v);
- }
- dis[v]=dis[u]+w;
- }
- }
- }
- ans=k-ans;
- }
- int main()
- {
- //freopen("C:\\Users\\Administrator\\Desktop\\1.txt","r",stdin);
- while(scanf("%d%d%d",&n,&m,&k)!=EOF)
- {
- init();
- for(int i=;i<=m;i++)
- {
- int u,v,w;
- scanf("%d%d%d",&u,&v,&w);
- add(u,v,w);
- add(v,u,w);
- }
- for(int i=;i<=k;i++)
- {
- int v,w;
- scanf("%d%d",&v,&w);
- mp[v]=min(w,mp[v]); //小优化,取最小
- }
- for(int i=;i<=n;i++)
- {
- if(mp[i]!=INF)
- {
- add(,i,mp[i],);
- add(i,,mp[i],);
- }
- }
- spfa();
- printf("%d\n",ans);
- }
- return ;
- }
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.
Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.
Jzzhu wonders how to get the maximum possible number of groups. Can you help him?
Input
A single integer n(1 ≤ n ≤ 105), the number of the apples.
Output
The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group.
If there are several optimal answers you can print any of them.
Sample Input
- 6
- 2 6 3 2 4
- 9
- 3 9 3 2 4 6 8
- 2
- 0
题意:给出n,表示数1到n,从中选出尽可能多的对数,两个数为1对,使得任意一对中两个数互质,并输出任意一种答案。
- #include <iostream>
- #include <cstdio>
- #include <queue>
- #include <cstring>
- using namespace std;
- #define INF 0x3f3f3f3f
- #define N 100010
- int n;
- int len;
- int vis[N];
- pair<int,int> p[N];
- void init()
- {
- len=;
- memset(vis,,sizeof(vis));
- }
- void solve()
- {
- int i,j,k,t,flag;
- for(i=;i<=n;i++)
- {
- if(!vis[i])
- {
- t=,flag=;
- for(j=i;j<=n;j+=i) if(!vis[j]) t++;
- if((t&) && i+i<=n && !vis[i+i]) flag=,vis[i+i]=;
- for(j=i;j<=n;j+=i)
- {
- if(!vis[j])
- {
- for(k=j+i;k<=n;k+=i)
- {
- if(!vis[k])
- {
- p[++len]=make_pair(j,k);
- vis[j]=;
- vis[k]=;
- j=k;
- break;
- }
- }
- }
- }
- if(flag) vis[i+i]=;
- }
- }
- for(i=;i<=n;i+=)
- {
- if(!vis[i])
- {
- for(j=i+;j<=n;j+=)
- {
- if(!vis[j])
- {
- p[++len]=make_pair(i,j);
- vis[i]=;
- vis[j]=;
- i=j;
- break;
- }
- }
- }
- }
- }
- void print()
- {
- printf("%d\n",len);
- for(int i=;i<=len;i++)
- {
- printf("%d %d\n",p[i].first,p[i].second);
- }
- }
- int main()
- {
- while(scanf("%d",&n)!=EOF)
- {
- init();
- solve();
- print();
- }
- return ;
- }
CodeForces 450的更多相关文章
- codeforces 450 B Jzzhu and Sequences
题意:给出f1=x,f2=y,f(i)=f(i-1)+f(i+1),求f(n)模上10e9+7 因为 可以求出通项公式:f(i)=f(i-1)-f(i-2) 然后 f1=x; f2=y; f3=y-x ...
- Codeforces 450 C. Jzzhu and Chocolate
//area=(n*m)/ ((x+1)*(k-x+1)) //1: x==0; //2: x=n-1 //3: x=m-1 # include <stdio.h> long long m ...
- Codeforces Round #450 (Div. 2)
Codeforces Round #450 (Div. 2) http://codeforces.com/contest/900 A #include<bits/stdc++.h> usi ...
- 【Codeforces】450 B(div2)
题目链接:http://codeforces.com/problemset/problem/450/B 题意: 求这个的第n项. 题解:$f_{i+1} = f_i - f_{i-1} $ \begi ...
- Codeforces Round #450 (Div. 2) D.Unusual Sequences (数学)
题目链接: http://codeforces.com/contest/900/problem/D 题意: 给你 \(x\) 和 \(y\),让你求同时满足这两个条件的序列的个数: \(a_1, a_ ...
- Codeforces Round #450 (Div. 2) C. Remove Extra One
题目链接 题意:让你去掉一个数,使得剩下的数的record最多,当1≤j<i的aj<ai1 \leq j< i的a_j<a_i1≤j<i的aj<ai时aia_i ...
- Codeforces Round #450 (Div. 2) ABCD
这次还是能看的0 0,没出现一题掉分情况. QAQ前两次掉分还被hack了0 0,两行清泪. A. Find Extra One You have n distinct points on a p ...
- Codeforces Round #450 (Div. 2) C. Remove Extra One【*模拟链表/一个数比前面所有数大就是个record。删掉一个数,让record的个数尽量多。】
C. Remove Extra One time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #450 (Div. 2) B. Position in Fraction【数论/循环节/给定分子m 分母n和一个数c,找出c在m/n的循环节第几个位置出现,没出现过输出-1】
B. Position in Fraction time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- java三线程循环有序打印ABC
迅雷笔试题: 编写一个程序,开启3个线程,这3个线程的ID分别为A.B.C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示:如:ABCABC….依次递推. 解决思路:每个线 ...
- OpenJudge/Poj 1321 棋盘问题
1.链接地址: http://bailian.openjudge.cn/practice/1321 http://poj.org/problem?id=1321 2.题目: 棋盘问题 Time Lim ...
- 实习笔记-1:sql 2008r2 如何创建定时作业
在公司实习了近一个月,学了很多东西.这一篇是一些比较基础的东西,本人是小菜鸟,不喜欢大神来喷.大神欢迎出门点右上角.谢谢~ 说大实话,对于数据库,我在还没出来实习的时候就是只懂写一些sql语句以及知道 ...
- GCC编译器入门
GCC(GNU Compiler Collection,GNU编译器套件),是由 GNU 开发的编程语言编译器.它是以GPL许可证所发行的自由软件,也是 GNU计划的关键部分.GCC原本作为GNU操作 ...
- 用C#开发一个WinForm版的批量图片压缩工具
我们在实际项目开发过程中,曾经遇到过一个需求,就是要开发一个对大量图片进行整理(删除掉一些不符合要求的图片).归类(根据格式进行分类,比如jpg格式.bmp格式等).压缩(因为有的图片很大很占空间,看 ...
- RAC,客户端连接失败ORA-12514
今天上午,某项目运维组的同事过来求助:"某系统的应用有问题了,WEB页面打开以后出现ORACLE的ORA-12514错误,貌似监听有问题了!" 该系统的数据是采用RAC部署的模式, ...
- This transaction has been rolled back, rather than only the current.
今天上午,收到运维组同事反映某应用系统的其中一个功能报错,不是偶然性事件,每个使用该功能的用户都报错.报错内容为:This transaction has been rolled back, rath ...
- C语言小知识
1.数组初始化 a[5] = {1}; //1,0,0,0,0 a[5] = {0}; //0,0,0,0,0 a[3][3] = {1}; //1,0,0;0,0,0;0,0,0 a[3][ ...
- 制作精灵(UI Sprite)
怎样判断是否应该使用精灵 在一套UI中,精灵是一种非常常见的元件.当制作UI时,如果需要显示一张图片,需要先判断这个图片是否应该制作到图集里去,然后用精灵的方式去使用它,一般来说,可以遵循以下规律. ...
- initialize or clean up your unittest within .net unit test
// Use ClassInitialize to run code before running the first test in the class [ClassInitialize()] pu ...